Am trying to post to facebook wall from an android app written with phonegap. I do get the following error: message:(#200) the user hasn't authorized the application to perform this action type:OAuthException. So my question is How do i get the user to authorize my app so i can post to their wall. I use this code to login:
function login() {
FB.login(
function(response) {
if (response.session) {
alert('logged in');
} else {
alert('not logged in');
}
},
{ perms: 'publish_stream' }
);
}
and i try to post with the below code which throws an error.
function postToWall() {
var body = 'Reading Connect JS documentation';
FB.api('/me/feed', 'post', { body: body }, function(response) {
if (!response || response.error) {
alert('Error occured ' + JSON.stringify(response.error));
} else {
alert('Post ID: ' + response);
}
});
}
Am using the phonegap facebook api from https://github.com/davejohnson/phonegap-plugin-facebook-connect and FB.ui does not work.
Thanks
Posting the same content throws errors so use a text type input for positioning content on Facebook, with post as the text type input:
function postdata()
{
var body = document.getElementById("post").value;
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error)
{
alert('Error occured');
}
else {
alert('Post ID: ' + response.id);
}
});
}
There are serious problems with that phonegap plugin right now. I'm really wishing it would be picked back up to fix them. One of the main issues is that oauth2 isn't supported and the plugin is using an older facebook sdk.
Related
If I'm logged into facebook the testAPI() function fires as it's supposed to, but when I log out of facebook and refresh the page where my init code is, nothing happens. My console should log "not logged in", or "not authorized", but it doesn't. I've tried clearing the cache, but it doesn't work.
FB.Event.subscribe('auth.authResponseChange', function(response) {
//this works
testAPI();
} else if (response.status === 'not_authorized') {
console.log("not authorized");
} else {
console.log("not logged in");
}
});
var testAPI = function() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
});
};
auth.authResponseChange only fires when the status actually change, in your case it never change.
What you want is to use FB.getLoginStatus.
Here is my code:
FB.ui({method: "permissions.request", "perms": 'publish_stream', 'display': 'popup'}, function (response) {
console.log(response)
console.log(response.perms)
}, {scope: 'publish_stream'});
And the result is always 'false', does anyone know the reason?
Thanks
The permissions.request dialog is not (no longer?) in the spec for FB.ui:
https://developers.facebook.com/docs/reference/javascript/FB.ui/
It seems that the only way to ensure that a user is logged in and has the required permissions for an action is to use a combination of FB.login() with the proper permission scope, and then FB.api('/me/permissions') to query the Graph:
FB.login(function(response) {
if (response.status === 'connected') {
FB.api('/me/permissions', function(response) {
if (response.data && response.data[0] && response.data[0].publish_actions) {
console.log("You got'em!");
}
});
}
}, { scope: 'publish_actions' });
Am working on facebook graph API for posting on facebook page.I have a webpage where each users can login and share contents on a facebook page.Consider certain organizations,each organization has there own facebook page.From my website any user having facebook account can come and share their feedbacks about that organization and that feedback should be posted in the facebook page of the particular organization.
I need to implement this using facebook javascript api,but am getting an error
The user hasn't authorized the application to perform this action","type":"OAuthException","code":200
Here is my code:
FB.api('/page_id/feed', 'post',
{
message : "It's awesome ...",
name : 'Feedback',
to: '',
from: '',
description : 'Your description'
},
function(response) {
if (!response || response.error) {
//alert(JSON.stringify(response.error));
console.log(JSON.stringify(response.error));
} else {
alert('Post ID: ' + response.id);
}
});
}
Please help
Thanks
Try this:
function login() {
FB.login(function (response) {
if (response.authResponse) {
// connected
postFeedBack();
} else {
// cancelled
}
}, { scope: 'publish_stream' });
}
function postFeedBack() {
FB.api('/page_id/feed', 'post', {
message: "My Feedback"
}, function (response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
I am successfully authenticating a user to Facebook through my Spotify app, but then I try to request the user information and my .getJSON callback is never called. Here's my code :
auth.authenticateWithFacebook(facebookAppId, facebookPermissions, {
onSuccess: function(accessToken, ttl) {
var request_url = 'https://graph.facebook.com/me';
var url = request_url + '?access_token=' + accessToken;
$.getJSON(url, function(data) {
alert("Working");
});
},
onFailure: function(error) {
console.log("Authentication failed with error: " + error);
},
onComplete: function() { }
});
I tried with $.ajax, adding &callback=?, &callback=myFunction but nothing ever worked... Anyone have an idea of the issue?
Thanks
Make sure you add graph.facebook.com to the RequiredPermissions key in your manifest.json file.
I dont know why but https://graph.facebook.com/132333806850364?access_token=218237124854683|VLsQV-ec2paQpq5hVMFFjtnk9_w returns false even though the app token is valid. The invitation was sent properly and I recieve invitations as well.
//Single user REquest
function sendRequestSingle(c_id,page_id,sendto,from,g_id) {
FB.ui({
method: 'apprequests',
to: sendto,
message: 'Win Mega Prizes!',
title: 'Enter in this contest!',
data: c_id+','+page_id+','+g_id
},
function (response) {
if (response && response.request_ids) {
var requests = response.request_ids;
window.location.href = "http://www.serverhere.com/contest/handle_invitations.php?invitations="+requests+"&contest_id="+c_id+"&page_id="+page_id+"&user="+from+"&g_id="+g_id+"&sendto="+sendto+"&single=1";
} else {
alert('canceled');
}
});
return false;
}