Since the REST API has gone, I need to find another way to read the likes for pages of our webapp.
According to the Graph API docs, the following should return the likes for any object (such as a page):
https://graph.facebook.com/v2.6/{PAGE-ID}/likes?summary=true
Oops, An access token is required to request this resource. Turns out, instead of a real token, you can also build an ad-hoc token witht the app ID and secret:
https://graph.facebook.com/v2.6/{PAGE-ID}/likes?summary=true&access_token={ID}|{SECRET}
The above returns a JSON payload, however, it's empty even though I'm trying this with a page having almost 200 likes:
{
"data": [
],
"summary": {
"total_count": 0,
"can_like": false,
"has_liked": false
}
}
Maybe a permissions problem? The app domain and the page URL domain are identical.
Big thanks for any hints to solve this riddle!
It does work with a simple App Access Token too, but i assume you get the wrong idea about that endpoint. There is no way to get the "Page Fans", you can only get "other Pages the current Page likes" with it. Just try this with your App Access Token:
https://graph.facebook.com/bladauhu/likes?access_token=APPID|APPSECRET
It should return the following JSON:
{
"data": [
{
"name": "FKK Scibes Skulls",
"id": "1391253501090151"
},
{
"name": "Dodgeball Austria",
"id": "387249994631552"
},
{
"name": "Turbojugend Scibes",
"id": "105248832848054"
},
{
"name": "HYDRA! Das endgute Satiremagazin.",
"id": "167084486537"
},
{
"name": "VLÜ Hydra",
"id": "113680962002559"
}
],
"paging": {
"cursors": {
"before": "MTM5MTI1MzUwMTA5MDE1MQZDZD",
"after": "MTEzNjgwOTYyMDAyNTU5"
}
}
}
More information about Tokens:
http://www.devils-heaven.com/facebook-access-tokens/
https://developers.facebook.com/docs/facebook-login/access-tokens/
https://developers.facebook.com/docs/apps/changelog#v2_6_changes:
The likes field on the Page node has been renamed to fan_count
As luschn said in their answer, likes are the other pages liked by that page; if you want to get the number of people that like the page itself, you need to request fan_count.
Related
We are building an app that manage Facebook comments for page admins. When managing the comments, we want to know if there is any "admin_notes" or "custom_labels" that the page admin has previously applied on that specific owner of the comment.
I imagine the API is something like this:
https://graph.facebook.com/v3.3/45013343238491111/comments?order=reverse_chronological&fields=message,from{name,id,custom_labels,admin_notes,likes}&access_token=...
The api above should theoretically return list of comments made on a post, with their owners name, id, and custom_labels etc.
But the comment listing response is like this:
{
"data": [
{
"message": "sdfsdfsdf",
"from": {
"name": "Dora Chan",
"id": "23424292416969420",
"likes": {
"data": [
{
"name": "Page name",
"id": "XXXXXX",
"created_time": "2019-05-29T06:03:42+0000"
}
],
"paging": {
"cursors": {
"before": "Mzg5OTgwNzQ4MjcxNzU3",
"after": "Mzg5OTgwNzQ4MjcxNzU3"
}
}
}
},
"id": "450133432384921_450162525715345"
},
{....
Information like "page likes" is available. But information like admin_notes and custom_labels are not available.
Why is that so?
Note:
I am using page access Token. All page related permissions are granted:
manage_pages, pages_show_list, publish_pages, pages_messaging, public_profile
If I call graph API on that specific user directly, i.e. https://graph.facebook.com/v3.3/[userid]?fields=name,id,likes,custom_labels&access_token=...
The outcome is same, I can see only name, userid, likes, but I cannot see custom_labels
I'm trying to get all comments from Facebook Comments Plugin running in my application.
Here's a step by step of what i have done
https://graph.facebook.com/{myUrl}
{
"share": {
"comment_count": 43,
"share_count": 1695
},
"og_object": {
"id": {myObjectID},
"description": {myDescription},
"title": {myTitle},
"type": "website",
"updated_time": "2018-05-28T21:50:37+0000"
},
"id": {myUrl}
}
https://graph.facebook.com/{myObjectID}/comments?access_token={pageToken}
{
"data": [ ],
"paging": {
"cursors": {
"before": {beforePointer},
"after": {afterPointer}
},
"next": {nextUrl}
}
}
So despite comment_count = 43, data field is empty.
It's also weird that a {nextUrl} is given although not showing any results.
Haven't found nothing about this in the recent update due to GDPR.
Any ideas?
The graph API has changed recently due to privacy and GDPR concerns.
To get all comments for a page or user first you need to make a call to get all your posts and then make a call for each post to get comments.
Please view the following example end to get all the posts and then post_ids (the call is similar for user posts).
https://graph.facebook.com/v3.2/{pageId}/posts?access_token={accessToken}
post_id looks something like this - 5704324444475_570454233326 and is in the id field of each returned post.
Then call the get comments endpoint from the graph API using the ID(s) returned by the first endpoint.
https://graph.facebook.com/{post_id}/comments?access_token={accessToken}&summary=true
You'll need to make a separate call for each posts to get that post's comments.
I'm currently building an experimental social network to study the influence of social medias on customers behaviors.
My users log in through Facebook OAuth provider. I store their access tokens and query the Open Graph API to fetch info about them.
I'm trying to use the all_mutual_friends edge for a given user context, using the access token of one of my users, but I found nowhere how to get the user-context-id that is required to get that info.
It is not the id of the user you want to retrieve the mutual friends from. I've tried that and got an error.
I've skimmed trough Open Graph docs and found nothing about that user-context-id.
How can I retrieve it?
Odly enough, the docs do not specify how to get the context id, but I managed to get it by digging a little.
This is how you would do to get the all_mutual_friends data:
GET /{user-id}?fields=context.fields%28all_mutual_friends%29&access_token={other-user-access-token}
Then, the context id would be given in the response.
{
"context": {
"all_mutual_friends": {
"data": [
{
"id": "1381033095543871",
"name": "Dave Amiaaehjighi Putnamwitz",
"token": <user token>,
"picture": {
"data": {
"is_silhouette": true,
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpf1/v/t1.0-1/c15.0.50.50/p50x50/10354686_10150004552801856_220367501106153455_n.jpg?oh=82c2ce067f9c7f2c0a66d1efb16730e7&oe=5670F72F&__gda__=1450287355_17925d7381c8da5663c2349483f4b032"
}
}
}
],
"paging": {
"cursors": {
"before": "MTM4MTAzMzA5NTU0Mzg3MQZDZD",
"after": "MTM4MTAzMzA5NTU0Mzg3MQZDZD"
}
},
"summary": {
"total_count": 1
}
},
"id": <Context id>
},
"id": "1375274282788732",
}
That context id could then be used for
GET /{user-context-id}/all_mutual_friends/
But this step is pretty useless since we get the data in the first query.
Would be nice if Facebook updated their docs to reflect reality.
I'm using the Facebook Graph API to fetch a public page feed. I created a basic application to get appId and secret. When I make a call to PUBLIC_PAGE_ID/feed I can retrieve the correct list of posts in JSON, but they are missing all the field I need, described in docs, and only have message, created_time and id:
{
"data": [
{
"message": "...",
"created_time": "2015-06-11T07:57:05+0000",
"id": "23X12XXXXXX9836_11XXXXXXXX610XXXX52"
},
...
Why all other data isn't there?
The response to your query: /id/feed is the default response. To access more data, you have to pass a fields parameter with the keyword of data you would like to retrieve.
For example: <id>/feed?fields=id,message,picture,shares
This will return:
{
"data": [
{
"id": "1234567890",
"message": "Message",
"picture": "http://fbcdn.com/xxxxxx.jpg",
"shares": {
"count": 0
}
}
}
What I could figure out is you should submit the app for review with at least one permission what your app still needs and then you will get back every data what you ask in the fields parameter.
Is it even possible to retrieve comments on Facebook ads through the API (Graph or FQL)? If yes, do I need a whitelisted app to do it? Also, if I have a page access token, is it enough, or I need a user access token with ads_management permission?
Regarding the token usage, a page_token is extended by a given user to a given app. The page_token will have at most the same privileges as the user on his authorized pages and ad_accounts.
Generating a page_token can be done automatically, in behalf of the user, if you already have a user_token with manage_pages permission. Again, this page_token will have at most the same privileges that the user_token you used to generate it.
In other words, having a page_token doesn't amount for any additional privileges than the ones already present in the user_token.
Having said that, you need
a token with access to a given ad_account
that the app for which that token was generated, has that ad_account active in its settings
If the second requisite isn't met, for example for ad_account act_123456789 you'll get the error:
{
"error": {
"message": "(#274) The ad account is not enabled for usage in Ads API. Please add it in developers.facebook.com/apps -> select your app -> settings -> advanced -> advertising accounts -> Ads API. Account 123456789 not enabled for this application.",
"type": "OAuthException",
"code": 274,
"fbtrace_id": "xxxxx"
}
}
You can try, for example, generating a token with all privileges for the Graph API Explorer App. It will throw the error above because said App doesn't have the ad_account act_123456789 enabled.
So, given you have a token with ads_read extended for an app that has this ad_account listed, and you know the ad_id, you can procede as I explained in thread Get comments from facebook ads (marketing)
Basically, you use the ad_id (for example 123000000) to get the promoted post id and its actions
/123000000?fields=creative.fields(effective_object_story_id),insights.fields(actions)
The answer will contain an effective_object_story_id (for example, let's say it is 456000000_789000000) and its actions broken down by type:
{
"creative": {
"effective_object_story_id": "456000000_789000000",
"id": "123000000"
},
"insights": {
"data": [
{
"actions": [
{
"action_type": "comment",
"value": "12"
},
{
"action_type": "like",
"value": "2"
},
{
"action_type": "post",
"value": "3"
},
{
"action_type": "post_reaction",
"value": "29"
},
{
"action_type": "video_view",
"value": "558"
},
{
"action_type": "page_engagement",
"value": "604"
},
{
"action_type": "post_engagement",
"value": "602"
}
],
"date_start": "2017-08-14",
"date_stop": "2017-08-20"
}
],
"paging": {
"cursors": {
"before": "xxx",
"after": "xxx"
}
}
}
}
If you want to also distinguish paid comments from regular comments, you can query the comments edge of the post_id 456000000_789000000 to get the overall comment count which should be greater than the comments generated by the ad.
You can't pull the actual words of the comment via the API - would make it too easy to scrape.
Yes, Facebook ads that have comments are because the ad is a promoted page post, whether that page post is hidden or not. Page post comments are available via the Facebook API and does not require having Ads API access. Use the graph API endpoint /v2.1/{page-id}/comments to retreive page post comments. See the Facebook Graph API documentation on object comments for more information.