Has Facebook deprecated the /EVENT_ID/invited part of their API? - facebook

I'm trying to figure out how to access the guest list data of an event on Facebook and the example given in the Facebook documentation located at https://developers.facebook.com/docs/reference/api/event/ is:
https://graph.facebook.com/331218348435/invited
However, when I test this in the explorer I get:
{
"error": "Request failed"
}
Am I missing something?

The endpoint is most definitely not deprecated.
The problem here is that there are simply too many people invited to that event! There are too many results to return in a single query...
If you specify a limit you will get the results you need:
https://graph.facebook.com/331218348435/invited?limit=10
The response for that request would be something like this :
{
"data": [
{
"name": "xxx",
"rsvp_status": "attending",
"id": "111"
},
{
"name": "yyy",
"rsvp_status": "attending",
"id": "222"
},
... (8 more results) ...
],
"paging": {
"next": "https://graph.facebook.com/331218348435/invited?limit=10&offset=10&__after_id=29606639"
}
}
Note that there is a paging result returned as well - this is the URL you will need to query in order to get the next batch of results. It uses the limit parameter and also the offset parameter to ensure that you don't get duplicate results.
In my example, I've given a limit of 10 users per response, but I've managed to get data even when specifying 1000 results. The bigger the limit you provide the longer the request will take to return data.

Related

Facebook Graph API get comments from Comments Plugin

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.

Permissions to Read Likes via Graph API

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.

Getting Facebook Post all Reactions Count in single Graph API request

As Facebook released the new reaction{NONE, LIKE, LOVE, WOW, HAHA, SAD, ANGRY} feature for post, but I can not figure out to get all reaction counts in single graph API request.
Has anyone figured out a way to get this detailed reactions per post in single request?
The approach introduced by #CBroe appears to be working using Multiple ID Read Requests.
?ids=7175346442_10153799389241443,7175346442_10153799470326443&fields=reactions.type(LOVE).limit(0).summary(total_count).as(reactions_love),reactions.type(WOW).limit(0).summary(total_count).as(reactions_wow),reactions.type(HAHA).limit(0).summary(total_count).as(reactions_haha),...
Screenshot from Facebook Graph API Explorer:
Once a collection of posts is retrieved, one should be able to read reaction counts grouped by type using a single request. Note, the current limit of ids in the Multiple ID Read Request pattern is 50.
Theoretically possible using Field Expansion in combination with Field Aliases, like this:
?fields=reactions.type(LIKE).limit(0).summary(1).as(like),
reactions.type(WOW).limit(0).summary(1).as(wow),
reactions.type(SAD).limit(0).summary(1).as(sad),…
But there still seem to be some bugs in that regard; I frequently got “An unknown error has occurred” while testing this; f.e. replacing the limit value for LIKE with 1 in the above query triggers it …
Simply use the following as part of your graph query
fbpageid/posts?fields=created_time,story,message,shares,reactions.type(LIKE).limit(0).summary(1).as(like),reactions.type(LOVE).limit(0).summary(1).as(love),reactions.type(HAHA).limit(0).summary(1).as(haha),reactions.type(WOW).limit(0).summary(1).as(wow),reactions.type(SAD).limit(0).summary(1).as(sad),reactions.type(ANGRY).limit(0).summary(1).as(angry)&limit=10
So I'll be getting Post ID, Created time, Story, Message, Share Count, reaction count (currently 6 reaction) using only 1 query. It works with APi v2.9 as well
If you have read_insights permission, you could get reactions in following way for feed or a post
fields=insights.metric(post_reactions_by_type_total).period(lifetime).as(post_reactions_by_type_total)
and you would get results like:
"name": "post_reactions_by_type_total",
"period": "lifetime",
"values": [
{
"value": {
"like": 10,
"love": 2,
"wow": 3,
"haha": 1,
"sorry": 1,
"anger": 2
}
}
],
I found a way to achieve this with 1 request:
GET /{userId}?fields=
posts.as(like){reactions.type(LIKE).limit(0).summary(true)},
posts.as(love){reactions.type(LOVE).limit(0).summary(true)},
posts.as(wow){reactions.type(WOW).limit(0).summary(true)},
posts.as(haha){reactions.type(HAHA).limit(0).summary(true)},
posts.as(sad){reactions.type(SAD).limit(0).summary(true)},
posts.as(angry){reactions.type(ANGRY).limit(0).summary(true)},
posts.as(thankful){reactions.type(THANKFUL).limit(0).summary(true)}
This way you will receive 7 lists of posts (one per each reaction). Example:
{
"like": {
"data": [<list of posts>]
},
"love": {
"data": [<list of posts>]
},
"wow": {
"data": [<list of posts>]
},
"haha": {
"data": [<list of posts>]
},
"sad": {
"data": [<list of posts>]
},
"angry": {
"data": [<list of posts>]
},
"thankful": {
"data": [<list of posts>]
},
"paging": {
"previous": "...",
"next": "..."
},
"id": "<userId>"
}

Getting the user context id for a Facebook Open Graph API query

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.

Facebook Graph API does not return full post data

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.