Facebook Graph API post comment fails - facebook-graph-api

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?

Related

Graph API: All Mutual Friends Returning Empty List

All mutual friends request made from my app server (node) (also tried the Facebook API explorer) suddenly started returning an empty array for the data field. I confirmed and validated my access token and appsecret_proof on the API explorer. Do you know what has changed or what the request below is missing?
Note: both users use the app and have granted user_friends permission.
I am using v2.12
request
{
url: 'https://graph.facebook.com/v2.12/{user-facebookid}?fields=context.fields(all_mutual_friends.limit(5000))',
qs: {access_token: 'XXXXX'
,
appsecret_proof: crypto.createHmac('sha256', clientSecret).update(accessToken).digest('hex')
}
Yep. Facebook has taken down the Graph API for page access tokens. The only way to retrieve data (or was a week or so ago), was a temporary user token that lasts about 2 hours. It's totally broken my band's schedule page. I've been through every avenue and even spoke with a facebook ad team employee on the phone that was aware of it. She seemed to empathize but had no solution for me. I would count on it being down for a while.
I have finally figured out a work around for this. On your fb application, you have to disable the secret key requirement. This can be found under the advance settings of your fb application console. It's called "
Require App Secret".
Once you generate a fb PAGE access token, you get a fb page token, and then extend it.
here is the token debugger:
https://developers.facebook.com/tools/explorer/
You can extend the access token programmatically as explained here:
https://developers.facebook.com/docs/facebook-login/access-tokens/expiration-and-extension
AND
https://developers.facebook.com/docs/facebook-login/access-tokens/#pagetokens
There is also an extend tool in the access token debugger.

Posting to my own facebook wall via Koala

I am trying to post to my own facebook wall. So I created an "app" in my
personal facebook page, and got the app_id, app_secret, etc.
I then did this code:
#oauth = Koala::Facebook::OAuth.new(app_id, app_secret, callback_url)
#token = #oauth.get_app_access_token
#graph = Koala::Facebook::API.new(#token)
foo = #graph.get_object('me')
However, I get this error:
An active access token must be used to query information about
the current user. [HTTP 400]
(Koala::Facebook::AuthenticationError)
The token is valid, I checked. I need to post to my OWN wall, not a
different user's. From what I've read in the documentation, I need an "app
access key", not a "user access key" to do this. I am somewhat new to
the facebook api list, so I think I'm missing something very basic.
You can use an app token instead of a user token to post to a wall as long as the user already granted the proper permissions to your application.
That is, in timeline
User grants app access to post with publish_actions
User access token supplied by Graph Login Flow
At this point, you can either use the user access token or application access token
In addition,
foo = #graph.get_object('me')
is not a POST request. It says, get the object from the graph named me. Further me will not resolve to anything if you are using an application token because there is no way for the application to tell which "me" in all the users in the app you are referring to. Thus you need to refer to the app scoped id for the user.
e.g
foo = #graph.get_object('4')
Where 4 is a numerical app scoped ID (4 will not work in your case you need to figure out the correct ID for your application). The correct call in koala will be something like
foo = #graph.put_connections("4", "feed", :message => "I am writing on my wall!")
My problem was that the user (in this case myself) has to allow access to my app to post to my wall.
The full OAuth process is described well at http://developers.facebook.com/docs/authentication/
But specifically, I need to get a URL that I have to visit and then say "yes" to the authnetication question. The code is here:
#oauth = Koala::Facebook::OAuth.new(app_id, app_secret, callback_url)
#oauth.url_for_oauth_code(:permissions => "publish_actions")
The URL will look something like this:
https://www.facebook.com/dialog/oauth?
client_id={app_id}&
redirect_uri={redirect-uri}&scope=publish_actions
Note, the URL has to specify what permissions you want to request from the user (in this case, permission to post to the wall). This permission request is specified under the "scope" variable. Note some version of the facebook api allow posting through the "publish_stream" scope and other versions require the "publish_actions" scope. More information about the permissions available under scope variable is available here: https://developers.facebook.com/docs/facebook-login/permissions/v2.0
When you visit the URL that is generated from the above statement, facebook will give you a message asking if that particular app has permission to post to your wall. You, of course, say "yes". After that, your facebook app can post to the facebook wall using the "app access token"
After that, it's easy to post to the wall with your app access token. The code that works for me is:
#oauth = Koala::Facebook::OAuth.new(app_id, app_secret, callback_url)
#app_access_token = #oauth.get_app_access_token
#graph = Koala::Facebook::API.new(#app_access_token)
foo = #graph.put_connections(facebook_user_id, "feed", :message => "Test message")

Graph API Javascript bug

Recently I am experiencing this problem.
When I click to register with facebook and I am logged in as a user, I can see my information correctly. But staying on the same page, if I log out from facebook in some other tab and click Register with facebook on my own site, I see this person profile picture. The url of this image is:
http://graph.facebook.com/undefined/picture?type=large
I am accessing graph API using APP
Kindly advise me the solution to the problem
Accessing a users data requires an access token, with out this token your call is getting undefined returned as a user, and with out the access token appended to the picture url it returns emphamous Unknown User.
refer to: http://developers.facebook.com/docs/facebook-login/access-tokens/
for requesting access tokens, and usage.
Example Only: https://graph.facebook.com/ShawnsSpace/picture?type=large&return_ssl_resources=1&access_token=users_access_token
My script cannot access FB script without Access token
FB.login(function(response)
{
//If the user is succesfully authenticated, we execute some code to handle the freshly
//logged in user, if not, we do nothing
if (response.authResponse)
{
FB.api('/me', function(response) {}
}
{scope:'email,user_events,friends_photos,user_about_me,user_birthday,user_hometown,user_location,user_location,user_relationships'}); });//fbclick
So, I think access token condition is already satisfied.

Deleting Wall Posts with Graph

I attempted to delete a wall post on a fan page using Graph. This appears to work fine for some posts, but for other posts, I get an Oath Exception (#200 Permissions Error). The posts I tested with were non-admins and the posts were made from facebook (not a 3rd part app). My app has publish_stream permissions. Any ideas? I am trying to build a page moderation tool for my client.
I have had success deleting posts on a fan page that were posted by non-admins using the page access token with manage_pages, publish_actions, and read_stream permissions. You may need to get an extended access token with setExtendedAccessToken() or server side request and use it to get the page_token.
To get a longer-lived Page access token, exchange the User access token for a long-lived one, as above, and then request the Page token. The resulting Page access token will not have an expiry time at all.
Extended page tokens.
I have found no documentation to support the code below, but it has been tested to work.
try {
$args = array(
'access_token' => $page_token
);
$deleted = $facebook->api('/'.$post_id, 'DELETE', $args);
} (catch FacebookApiException $e) {
echo $e->getType() . " " . $e->getMessage();
}
If you don't have the post_id you can query the posts:
$facebook->api('/'.$page_id.'/posts?fields=id');
In Facebook, an object posted by a user or those posted by others in an object owned by the user ( holder of the access token specified) can only be deleted. The same is the normal behaviour of Facebook.
Just make sure you are trying to delete those objects posted by the owner of the Facebook access token.
Eg. A user can delete content on his wall, events created by him, comments or posts by others in events created by him, or those comments or posts created by him in others walls or objects.

Facebook Open Graph Beta: OAuthException

Trying to test the new Open Graph Beta to post a new action.
I'm following the official tutorial
It says to publish an action you would use this POST
For example, sending a POST to:
https://graph.facebook.com/me/YOUR_NAMESPACE:cook
?recipe=OBJECT_URL&access_token=ACCESS_TOKEN
But in the JS call. There is no access token
FB.api('/me/YOUR_NAMESPACE:cook' +
'?recipe=http://example.com/cookie.html','post',
function(response) {
..........
}
I get an error when i try to publish my own action. I have authenticated the publish_actions permission with the app
"OAuthException" - "An unexpected error has occurred. Please retry your request later."
It might be possible you are not posting to the correct object.
As in example 'cook' is action and 'recipe' is object..So the 'OBJECT_URL' must be of type 'recipe' as far as tutorial is concerned.
Since timeline is not launched therefore when you create your own object facebook provides you a sample url of that type which can be used to test the posting of your app.