I have a Facebook app with namespace 'thenovel'. It has an action 'rate' assigned to an object 'sentence'. When the 'dofacebookstuff()' function is called, I want the user's rating of a sentence - 'testsentence', for the moment - to be published to their timeline. 'Rating' doesn't require an access token.
Whenever the dofacebookstuff() is called, the error alert pops up. I have tested whether the '!response' or 'response.error' was causing it, and it is the 'response.error' every time.
I can get the user id, name etc. fine with FB.login but the api call just does not work. If I go straight to 'https://graph.facebook.com/me/thenovel:rate?sentence=testsentence&access_token=XXXXX', I see the following:
{
"data": [ ],
"paging": {
"next": "https://graph.facebook.com/me/thenovel:rate?sentence=testsentence&access_token=XXXXX&offset=25&limit=25"
}
}
I have checked my HTML and all the Facebook-related stuff is there and in the right place. None of the other scripts on the page produce errors. Here is the function in question:
function dofacebookstuff() {
FB.api(
'/me/thenovel:rate?sentence=hello&access_token=' + accesstoken,
'post',
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Action ID: ' + response.id);
}
});
}
Could anyone explain where I'm going wrong? Where is my response data?
If you're posting to /me you need an active access token for that user - do you have one? it may have expired already, but i think the message is specifically referring to the fact that you haven't provided one, as there'd be a specific message if the token is invalid or expired.
You should be able to post to /USER_ID/thenovel:rate with the app access token if you're doing offline publishing of some kind
Try logging in using FB connect first.
Related
I'm trying to send private replies as a page with the Graph API:
FB.api( '/' + id + '/private_replies', 'post',
{ message: message, access_token: token }, function(res) {}
);
The comment id is fine. The access token has been generated correctly. I have read_page_mailboxes permission. Despite all that, the API throws back this:
{
"error": {
"message": "(#10903) This user cant reply to this activity",
"type": "OAuthException",
"code": 10903,
"fbtrace_id": "BW3yOdmwnhi"
}
}
Am I missing something?
The problem appears to be the fact that I tried to reply to my own comments. That is not allowed. Only comments from others are allowed to reply to. Also, once replied to, the comment cannot be replied to ever again. That will throw a (different) error as well.
I also encountered the same problem. The reason might be your page is not published yet.
I'm trying to reply to a page via the Facebook API.
I can reply to the page via the Graph API. Have Application up the top right set to my App. Get my page token, enter "/{conversation-id}/messages", switch to POST, Click Add field, then a add key value pair - "message" "this is my message", click submit and it works, the message appears in the chat.
When I try to reply via my app, it appears to go through, I get no errors and the uuid of the message is returned to me once it has been submitted. It does not appear in the chat, I either get my page icon, like sending an empty message, or I get a message
"Attachment Unavailable This attachment may have been removed or the
person who shared it may not..."
If I take the uuid of the message and check on the Graph API, I can see that the message was indeed created, but the "message" field is empty, like it was stripped out.
The code I am using in my app:
postMessage: function($scope, pageToken, thread, message){
FB.api("/"+ thread +"/messages", "POST", {"message": "message"},
function (response) {
if (response && !response.error) {
console.log("Success")
}else{
console.log("failed")
}
}, {access_token: pageToken}
);
}
Not sure why this is happening and I couldn't find anything online about it.
Any help would be greatly appreciated.
Thanks,
Barry
I figured it out, and it was a simple oversight on my part, I needed to pass the access_token in just after the POST, rather than at the bottom of the function.
postMessage: function($scope, pageToken, thread, message){
FB.api("/"+ thread +"/messages", "POST", {"access_token": pageToken, "message": "message"},
function (response) {
if (response && !response.error) {
console.log("Success")
}else{
console.log("failed")
}
}
);
}
First of all, I'm aware there are plenty of questions and answers relating this topic. However, none of them works for me (maybe because they are old and the methods have become outdated, I don't know)... Let me briefly explain my problem:
I've been trying to login to Facebook with extended permissions on CocoonJS for about two weeks and I'm completely unable to do it... I can successfully login with basic permissions and everything works as expected, but I can't figure out how to request for extended permissions... When calling the Cocoon's FB login with the optional params, only the basic permissions are requested, so actually it seems that Cocoon (or FB) ignores the extended requests:
var socialService = CocoonJS.Social.Facebook.getSocialInterface();
socialService.login(function(loggedIn, error) {
if (error) {
console.error("login error: " + error.message);
}else if (loggedIn){
console.log("login suceeded");
CocoonJS.Social.Facebook.getLoginStatus(function(response) {
if (response.status === 'connected')
CocoonJS.Social.Facebook.api("/me/permissions",
function (response) {
if (response && !response.error) {
console.log("Granted perms.: "+JSON.stringify(response));
}else{
console.log("ERROR: unable to retrieve permissions");
}
}
);
}
});
}, { 'scope': 'user_photos,publish_actions',return_scopes: true });
The thing is, the login function seems to work properly and the "login succeeded" log is printed, and so is the "Granted perms." log. However, it only shows the basic permissions, completely ignoring the 'user_photos' and the 'publish_actions' ones (they don't even appear in the retrieved list...
I tried calling the option with 'scope', with scope, with 'perms'... but nothing changes the result. I've asked in the CocoonJS forums, I've been googling for two weeks, tried different solutions, different Facebook accounts, even tried hardcoding the extended params in the CocoonJS's FB login function (which result in crash), but nothing works...
Anyone knows how to achieve it?
Thanks in advance for your time and effort!
CocoonJS parses the 'scope' parameter as a string with comma separated values. But these permission values are used with a readonly session login. Facebook has deprecated logging in with the "publish_actions" permission and suggests that an app should request the bare minimum of read permissions during login and then request any additional or publish permissions when a person actually needs them.
I recommend that you request extended permissions this way:
CocoonJS.Social.Facebook.requestAdditionalPermissions("publish", "publish_actions", function(response) {
callback(response.error ? false : true);
});
According to the FB SDK docs, it appears that some data from the response object I should be able to retrieve sans access token. (https://developers.facebook.com/docs/reference/api/user/) However when I do this, I receive the message in the response object -
An active access token must be used to query information about the current user.
Does anyone have any insight on the matter?
Thanks a ton!
EDIT - the code I'm using:
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function (response) {
console.log('Good to see you, ' + response.name + '.');
console.log(response);
});
}
My finding so far indicate that basic information cannot be accessed unless one has either 'userid' or 'username' as in this post.
If one has to try and fetch basic information using following url, then access_token is needed
facebook
{
"error": {
"message": "An active access token must be used to query information about the current user.",
"type": "OAuthException",
"code": 2500
}
}
We have some code on the site to request additional permissions, specifically Posting to Timeline, when a user performs an action. This has been working fine until recently, where the response format from FB has changed. I've included the sample code below:
FB.ui({
method: 'permissions.request',
'perms': 'publish_actions',
'display': 'popup'
}, function (response) {
var confirm = response != null && response.perms != null && response.perms != '' && response.perms.indexOf('publish_actions') !== -1;
$('.close').click();
});
Previously, the response from this would be parsable as a string to confirm whether the user accepted the escalated permissions. However, regardless of whether the user accepts or rejects, it's just returning 'false' now.
Does anyone know if we're doing something wrong, if something has changed on FB's end, etc. Really struggling to know where the issue lies.
Probably it's latest changes in facebook api.
so, check out a new doc page and I wish you will change the process of getting permissions to login:
FB.login(function(response) {
// handle the response
}, {scope: 'email,user_likes'});
here, you can find a list of permissions and add to scope whatever you need, for example:
FB.login(function(response) {
// handle the response
}, {scope: 'email,publish_actions'});
that will allow to your app to post content, comments, and likes to a user's stream and to the streams of the user's friends.
I hope that helped somehow - let me know.