I have a web application that uses Facebook API. Now, I'm facing with an issue on getting the total of likes from a user's post.
I have a long lived "userToken" valid for 2 months with the following scopes: public_profile, email, manage_pages, publish_actions
I use "POST /feed" to send a link into the user's timeline and I get a post ID.
Then, I try to get the total of likes for this post with "GET /{POST_ID}/likes?sumary=true" and I get ZERO likes even if the post has many likes.
{
"data": [
],
"summary": {
"total_count": 0
}
}
I tried to use only "GET /{POST_ID}" to get post information and I get the following json response:
{
"error": {
"message": "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100
}
}
I have this issue only when I post to a user's timeline. However, when I post to a Facebook page, I can get the post ID and the numer of likes.
I made a test by adding read_stream scope and I can get the post information. However I read in API documentation that this permission has a limited use: "This permission is granted to apps building a Facebook-branded client on platforms where Facebook is not already available"
Then, I started to check other applications that get post likes and I noticed that they are using only public_profile, email, manage_pages, publish_actions. They are not using read_stream.
So, my question is how they can get this information only with these scopes?
I hope anyone of you will be able to help me?
Thanks
Can you please check, if the post is public.
If you have the post id of a public post you can fetch the likes simply by requesting the endpoint you already mentioned.
To get your feed you need the read_stream or user_posts permission.
Related
I'm using the Graph API Explorer to reply the comments on fan page via my app.
It works only the page is published. However, it bothers me so much.
How do I to test the app before publishing the page?
What I'm trying to do is the app will listen to the webhook from Facebook and then reply to the comment as long as got a comment.
I've been search for a while, there's very few questions related to this. Any suggestion would be thankful. ;)
// POST
https://graph.facebook.com/{comment-id}/comments
// response when the page is unpublished
{
"error": {
"message": "(#200) Cannot access object_id: {comment-id}",
"type": "OAuthException",
"code": 200,
"fbtrace_id": "{fbtrace_id}"
}
}
Confirmed that you can't access the comments while unpublished as the page id prepends the comment id. I would say quickest and easiest way to test is to just create a separate test page and keep that published.
I am testing the facebook graph API comments
https://developers.facebook.com/docs/graph-api/reference/v2.12/object/comments
I checked my permission for the access token it contains the permission, which required by API. see the screenshot
I test my object-id (1797963943566411_1975256375837166) which is correct see me screenshot
Change the request method to POST and adding post data {"message": "haha"}
I get the error message shows:
"(#3) Publishing comments through the API is only available for page access tokens" see my screenshot
As you can see the first step checking, I have all the permission that the
API required.
Can any one see any sort of error in this process?
Try another way still not work.
I have a user who post a photo on his own facebook page.
I logged in with this user and give this user all permissions see the screenshot
enter image description here
call /me/accounts to get page access token
enter image description here
copy the page access token into the Graph API Explorer's access token field
call
GET: 1797963943566411_1975256375837166/likes
is working fine
But call POST: 1797963943566411_1975256375837166/likes
Get error response:
{
"error": {
"message": "(#200) Permissions error",
"type": "OAuthException",
"code": 200,
"fbtrace_id": "GtEaBfyXrUD"
}
}
The reason is Facebook changed the API behaviour. We are no longer to use api to like any POST on our time line. API can only like or comments on facebook page. Sad face !!!!
Previously - we were able to use the /account_id?acesss_token=APP_ACCESS_TOKEN to get the users information that authed in your app.
For the new v2.0 API, we get app_scoped_id where the folllowing method:
https://graph.facebook.com/v2.0/APP_SCOPED_ID?access_token=APP_ACCESS_TOKEN
Works for some users, but others - we get this:
{
"error": {
"message": "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100
}
}
Why would this function work for some users, but not others? We have no way to get the link property of the user to redirect them, nor does http:///facebook.com/SCOPED_APP_ID do anything or http://facebook.com/app_scoped_user_id/SCOPED_APP_ID work correctly. Anyone have advice to redirect the user to their FB profile via the FB Scope App ID?
I am fetching my timeline from Facebook and I successfully able to get my timeline but when I login with my friend's Facebook account I received the following error-
{
"error": {
"message": "(#200) Requires extended permission: read_stream",
"type": "OAuthException",
"code": 200
}
}
I am the admin of the application on Facebook developer but my friend is not.
I have already approved following permissions from Facebook(see attached screen shot)
And below is the permission which I am using in my code-
FBSession* sess = [[FBSession alloc] initWithPermissions:[NSArray arrayWithObjects:#"public_profile",#"user_friends",#"user_birthday",#"email",#"user_education_history",#"user_work_history",#"user_hometown",#"read_stream",#"user_about_me",#"user_posts",#"publish_actions",nil]];
And here is the code to getting the timeline-
NSString *urlStringFacebook = [NSString stringWithFormat:#"https://graph.facebook.com/me/home?format=json&&access_token=%#&&limit=90",[[FBSession activeSession] accessTokenData]];
If I submit the read_stream permission to Facebbok for review the reject it due to the following reason(see screenshot below)-
And one more thing when I login with my account they ask me to allow for news feed(read_stream) permission but when my friend login they don't ask for that permission.
When I try to get the same thing on Graph API explorer then the data comes fine.
Please let me know what I am missing in the whole process.
Thanks
You are trying to use /me/home, which needs read_stream as you can read in the docs: https://developers.facebook.com/docs/graph-api/reference/user/home
...and that permission will not get approved: https://developers.facebook.com/docs/facebook-login/permissions/v2.3#reference-read_stream
Use /me/posts or /me/feed instead, those endpoints need user_posts and you got that permission approved already: https://developers.facebook.com/docs/graph-api/reference/v2.3/user/feed
Btw, this is explained very well in the changelog: https://developers.facebook.com/docs/apps/changelog#v2_3_new_features
You can get Home Timeline post using user_posts.
Using /me/feed you can get all post from others and you. go to Developer graph API Explorer Graph API Explorer.
Use /me/feed instead of /me/home, with the already granted user_posts permission this should work. This endpoint also returns other posts from the user's timeline, not only those from the user himself (/me/posts)...
I try to retrieve post's information from Graph API:
https://graph.facebook.com/100006679472813_1392957120936924?access_token={my_access_token}
The Facebook Graph response:
{
"error": {
"message": "Unsupported get request.",
"type": "GraphMethodException",
"code": 100
}
}
However, I can access the post by this link (same user as {my_access_token}) https://www.facebook.com/100006679472813_1392957120936924
And I can receive the original message of this post via Graph Search API too.
Not all posts return error. But so many do. How can I get it's detail via Graph API?
You can not read all the posts in the facebook. If you try to fetch the details of the post by the user other than the user in the session, you may or may not get the details of the post. This depends on the privacy settings of the user. So, only the public posts can be fetched (in case of other users)