Facebook Open Graph Beta: OAuthException - facebook-graph-api

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.

Related

Create Facebook test page

I'm trying to create a test page on Facebook while developing an app. Per the instructions, I've created a test user, noted the user id and created an access token.
I'm now trying to make a POST request via curl to create a page
curl -i -X POST https://graph.facebook.com/v3.3/{user-id}/accounts?category_enum=MARKETING_AGENCY&name=Test%20Page&access_token={access-token}
However the response is an error
(#100) The parameter name is required
Seems I have supplied the name parameter though; any ideas?
EDIT
If I remove the category_enum param, the error becomes
(#283) Requires manage_pages permission to manage the object
However, I have verified the user has the manage_pages permission....
Beware of the facebook api documentation... On the surface it looks like only the name parameter is required, however after hours of experimentation with the Graph API Explorer I managed to create the test page with no less than 9 required parameters!

Media Builder Not Found Exception while Publishing into Instagram using Graph API

We are oftenly getting "Media Builder Not Found" Exception while publishing media using Instagram Graph API.Can anyone know how to fix it?
Triggered URL:
Url1 : https://graph.facebook.com/v2.10/<userId>/media?access_token=<token>&image_url=<imageUrl>
&caption=<caption>
Url2 : https://graph.facebook.com/v2.10/<userId>/media_publish?creation_id=<creationId>&access_token=<token>
Yeah, this is tricky and sad - Facebook really has outdone itself here. The issue is that uploading to Instagram using Facebook API requires 2 types of access tokens.
When you call /media endpoint to upload an image, a user access token must be used.
When you use /media_publish to publish a previously created image - you must use page access token
Good luck!
I had the same issue, in my case, using the page token to create the media object and then using the user token to publish it, solved it.
What's strange though is that before I got the Instagram permissions approved, everything worked just by using the page token...but after I got the permissions approved it started failing and I had to use the user/page token combination to make it work.

Unable to find Facebook Page Insights using Page Access Token in RestFB

I have to develop an automated process for fetching my Facebook page insights. Since, Access token used for authentication purpose is temporary in nature. Therefore, I created a Facebook App and by providing all required permissions I generated a Page Access Token so that I could extend it's life-span.
Reference Link : Java + RestFB API: Getting fresh Page Access Token without messing with AppID, appSecret
The following is my piece of code :
FacebookClient fb=new DefaultFacebookClient(accesstoken,Version.VERSION_2_7);
Connection<Insight> insights =fb.fetchConnection("119456244790112/insights", Insight.class,Parameter.with("since", "2016-08-01"),Parameter.with("until", "2016-08-27"));
for (Insight insight : insights.getData())
if(insight.getName().equals("page_impressions") && (insight.getPeriod().equals("day")) )
System.out.println(insight.getName()+"\t"+insight.getPeriod()+"\t"+insight.getValues());
'accesstoken' is the short-life Page access-token obtained by following the mentioned link.
The following is the Exception Stack I'm getting :
Exception in thread "main"
com.restfb.exception.FacebookOAuthException: Received Facebook error
response of type OAuthException: Invalid query (code 3001, subcode
1504028) at
com.restfb.DefaultFacebookClient$DefaultGraphFacebookExceptionMapper.exceptionForTypeAndMessage(DefaultFacebookClient.java:1191)
at
com.restfb.DefaultFacebookClient.throwFacebookResponseStatusExceptionIfNecessary(DefaultFacebookClient.java:1117)
at
com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:1058)
at
com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:969)
at
com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:931)
at
com.restfb.DefaultFacebookClient.fetchConnection(DefaultFacebookClient.java:356)
at Main.main(Main.java:31)
Please help me finding the Page Insights using Page Access Token and hence extending it's life-span so that I could produce an automated process out of this. Thanks !
You asked two questions in one.
Extending an access token:
First, you need the user access token. Than extend it (Check the RestFB manual: http://restfb.com/documentation/#access-token-extend) and take the page access token for the page from /me/accounts. The page access token has an unlimited lifetime.
The OAuthException:
If you look at the error message of the exception you should see that the metric is missing. You nee to tell Facebook what metric you like to get. Check the Graph API Reference for valid metrics: https://developers.facebook.com/docs/graph-api/reference/v2.7/insights
Finally I got the success in pulling the Page Insights data using the 'Page Access Token' with extended life-span.
The following is the snippet for making the appropriate requests to Facebook :
Connection<Insight> insights =fbclient.fetchConnection("1388062484542431/insights/page_views/day", Insight.class,Parameter.with("since", "2016-08-01"),Parameter.with("until", "2016-08-30"));
If multiple Metrics need to be passed then we can do so by passing comma-separated names of the required Metrics.
Thanks.

Facebook Graph API v2.5 - Impossible to delete post created with a link

I'm using Facebook Graph API v2.5 to publish and delete posts from user's profiles.
I'm using Postman (Chrome extension) to test my REST calls.
Case 1) When all actually works:
- I do a POST request to "https://graph.facebook.com/v2.5/MY_USER_ID/feed", with params "access_token" and "message"
- The API returns me the created post ID, let's say "108373569531356_138530589848987"
- Then I do a DELETE request to "https://graph.facebook.com/v2.5/108373569531356_138530589848987", with params "access_token".
- My message I successfully removed from user's profile
Case 2) My issue, it does not work as expected
- I do the same POST request as previous, but I add an extra "link" parameter.
- The API returns me the created post ID.
- Then when I try to delete this post using DELETE request, the Facebook API throws me an error: "message": "(#100) This post could not be loaded"
One thing I noticed, is that first request seems to create me a Facebook "post", but the second one seems to create a "link".
I used the v2.3 API get/post_id to compare both posts, they are pretty much different.
So, why can't I delete a "link" element, the Facebook documentation does not tell anything about it.
Many thanks !
Maybe you were suffering a bug (https://developers.facebook.com/bugs/1671530079772375/) which is fixed now.
If you published a post with a link through an app being in development mode, this post wasn't credited to your app [bug] so, if you tried to delete it, you couldn't because Facebook only allows to delete posts published by your app.

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?