publish_actions vs publish_stream issue while submitting open graph - facebook-graph-api

I have my application up which asked for the following permissions:
email,user_birthday,status_update,publish_stream,offline_access
I've implemented open graph now and tested it. It works perfectly, but after submission I have the following message from facebook
Your code is currently configured to publish a stream story. You must
change your code so that when the test user triggers the action it
produces an open graph story. Please make the appropriate changes and
resubmit.
From this blog post on facebook dev blog from april, it seems that 'publish_actions' is a subset of 'publish_stream' based on that I have some questions.
If that is true why do I need the publish_actions permission?
Do I need to take publish_stream out and put in publish_actions? But my game uses publish_stream to publish images from the game to albums. Which it will still be doing. What do I do about that?
How do I ask users for publish_actions at run time for these permissions if required and authenticate them without a reauthentication or reload. Any resources on that?
And for clarity here is my open graph publishing code
FB.api(
'/me/'+fAction,
'post',
sObject,
function(response)
{
if (!response || response.error)
{
for (var prop in response)
{
console.log(response[prop]);
callbackToFlash(0);
}
} else
{
console.log('success'+object);
callbackToFlash(1);
}
}
);

Related

Facebook API: Post on Facebook wall is not working

I'm a Facebook app developer. I have developed some apps. Everything was working good.
I have not developed any apps for the past 6 months. Now I started to develop an app with existing code. It is not working like what I expected. I don't know why. I have checked the coding with old apps. Everything is fine.
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
} else {
loginUrl = "https://www.facebook.com/dialog/oauth/?client_id=" + appId + "&redirect_uri=https://apps.facebook.com/appname/&scope=email,user_activities,user_likes,publish_actions,read_stream,publish_stream";
top.location.href = loginUrl;
}
}, true);
I couldn't post on my facebook wall. Error ((#200) The user hasn't authorized the application to perform this action) is coming.
Please advice.
The authorization did not work. Use FB.login for authorization: https://developers.facebook.com/docs/reference/javascript/FB.login/v2.1
Important note: Call it on user interaction, and NOT in the (asynchronous) callback function of FB.getLoginStatus. You should not directly present the authorization screen/popup to the user right when he opens your App/Website anyway.
Also, publish_stream is deprecated, publish_actions is the only permission you need for posting.

Without using cordova plugin post message on Facebook

Using this link facebook-phonegap-cordova-without-plugin I create an phonegap Facebook app. In that app application when I am login that application it working fine. It give me facebook friendlist, birthday, friend links and its allow to me to post on Facebook wall me and my friends Facebook wall. but when I logout and logging into another user then it allow me to login but its gives me that message The User hasn’t authorized the application to perform this action. And when I try to post some thing then it gives me that error This does not let testing post to Facebook your public profile is you name, profile and other public info
I am using
latest cordova build
In developer.facebook my application name is Testing
I am using API v1.0
following code is to share the post
function share() {
openFB.api({
method: 'POST',
path: '/me/feed',
params: {
message: 'Testing Facebook APIs',
},
success: function() {
alert('the item was posted on Facebook');
},
error: errorHandler});
}
Please remember its working fine for me but when I logging using another user then it gives me error.
Have you tried this while logging out the first user :
Revoke permissions :
openFB.revokePermissions(
function() {
},
errorHandler );
If it's working for you only then check if your app is in developer mode or not.
Go to your app facebook dashboard.
App review tab.
Check and turn on to make your app public.
Hope it helps with your question.

Facebook Graph API post comment fails

I'm using the FB graph API to post comments on different posts, but it does not work every time. There are posts that are okay to be "commented" and others fail every time. I'm using a Facebook user auth token (not a group or app token) to post comments.
The error returned is (#200) Permissions error.
At first I thought the post is not public and my user don't have a permission to comment on it, but when I go to it via web browser and logged in as the same user - he can manualy post comments on it. So via web it is working and via API it produces permissions error #200.
And just to mention again - I'm able to comment on certain posts with no issues.
Here is sample of my code that I think it is a fairly standard:
$oFacebook = new Facebook($config);
try {
$oFacebook->api('/'.$iEventId.'/comments', 'POST', array(
'message' => $sComment,
'access_token' => $sAccessToken
));
} catch (Exception $e){
print_r($e->getMessage());
}
$sComment is small plain text.
$sAccessToken is saved in DB access token. When I test it in the FB debug tools it says the token has publish_stream scope which is needed to post comments.
The same situation can be reproduced via Graph API explorer, so I assume it is not code-related issue.
In terms of reproducibility, here is one post ID that CAN'T be commented via API: 381578255242674. You can generate random access token in the explorer and try to POST to /381578255242674/comments.
And here is one post ID that CAN be commented: 265070490272041.
Any suggestions?

Why is the Facebook API returning an empty array for albums?

I'm fairly new to the Facebook API, but I've tried to do my due diligence to figure this out, but I can't seem to. I'm simply trying to get a list of the logged-in user's albums, using various techniques, to no avail. I'm using the JavaScript SDK, and I have the following code:
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId:'{MY_APP_ID}',
cookie: true,
status: true,
xfbml: true,
oauth : true
});
FB.login(function(response) {
if(response.status === 'connected') {
FB.api('/me/albums', function(response) {
console.log(response);
});
}
}, { scope : 'user_photos' });
</script>
Note that {MY_APP_ID} is actually my application ID. So, when this executes, the popup will request access to the users photos, and that works fine. Now, in code, response returns a data array that contains no elements. In addition to trying the above, I've tried initiating a JSON request to the following URL as well as directly visiting it in the browser:
https://graph.facebook.com/me/albums?access_token=" + response.authResponse.accessToken
And this returns an empty data array as well. The access token that I'm using is coming either from the FB.login method or FB.getLoginStatus. Any help would be greatly appreciated. Thanks in advance.
So, I figured it out, so I will answer my own question. All the other answers on SO was related to permissions, but this wasn't it. It turns out that if I looked at my account settings (I'm the 'user'), and looked at apps, for this application, for some reason, it showed it only was requesting the email address. I knew this wasn't correct, because I was clearly asking for user_photos as well. So, after deleting the application from my profile, and reinitiating the connect, it looks like I'm able to access the albums fine. I'm not sure if Facebook intended to do this by design, but it seems like a potential bug to me.
This can also happen if you're using the JS SDK, as that authentication process and auth dialog are apparently complete separate from what you set up in the developer app.
You need to ALSO include the permissions you desire when you call FB.login() using the optional scope parameter, eg...
FB.login(function(response) {
if (response.authResponse) {
M.FB.setIsAuthorised(true);
// On success.
} else {
// On failure.
}
}, {
scope: 'email,friends_birthday,user_photos,friends_photos,publish_actions'
});
I had a similar issue. Several solutions on stackoverflow mostly attributed the issue to the lack of required permissions. Check the permissions you need by using the Graph API explorer or documentation (The tables have a column called permissions for each field).
Jonathan's solution actually gave me a clue about where I went wrong. I had a different issue where I had double-checked all the permissions set for my app dashboard that were correct, but while logging in, I had specified a scope with a set of permissions which seemed to override the app settings. :( I found this strange, but I rectified it by including the other permissions in the scope too and my problem was resolved.
An effective way to see if the right permissions are being set through the code is to use the following code:
FB.api({ method: 'fql.query', query: 'SELECT user_status,friends_status,user_photos,friends_photos,user_location,friends_location FROM permissions WHERE uid=me()' }, function(resp) {
for(var key in resp[0]) {
if(resp[0][key] === "1")
console.log(key+' is granted');
else
console.log(key+' is not granted');
}
});
P.S: Also make sure that if you changed the permissions in the app dashboard, you log out of your application and login again before testing.
I wasted over 3 hours trying to fix this issue and facebook documentation did not help me a bit, so hope this helps someone!

Facebook graph api

how to give publish_stream permission?If i trying to post on own wall,still it is saying that user is not authorised the application to do this action.I don't have any app.
There are a few ways to do it. Personally I would use the Javascript SDK.
Another way is to update your Facebook App settings (using Facebook Developer App) to require users to permit Extended Permissions 'publish_stream'.
Below is code using the Javascript SDK FB.api function:
FB.login(function(response) {
if (response.authResponse) {
// user is logged in and granted some permissions.
console.log("user is logged in and granted some permissions.")
} else {
// User cancelled login or did not fully authorize.
console.log("he failed to login or something")
}
}, {scope:'publish_stream'});
Inside scope: you can put a comma-separated string of permissions, if you want to ask for multiple.