Facebook Graph API: unable to get shared posts although share count is higher than zero - facebook

I'm experiencing a weird behavior from the graph API: i want to list shares of a shared posts, so i'm requesting /<post_id>/sharedposts?fields=shares to get the number of times a shared posts has been subsequentially shared.
The response i'm getting, thus, is a list of objects like this:
{
"shares": {
"count": 1
},
"id": "136178893505927_155012298289253"
},
However, if i request /136178893505927_155012298289253/sharedposts, I get
{
"data": [
]
}
Which is weird, as I was expecting one object to be in the response.
Moreover, if I request /<post_id>/sharedposts?fields=shares,sharedposts i'm getting a weird list containing shares.count higher than 0 and no sharedposts content in some cases and a sharedposts array containing less elements than shares.count in some others.
I'm guessing this happens because the shared posts are not visible to my profile, but shouldn't I be able to see them, since the original post was published on a page I manage?
I'm trying to build the graph of shares to determine if a share being re-shared contributed more than others to the overall share count, but it looks like this is not feasible with the graph API...or am I missing something?

Use Graph api v2.3 and you need read_stream permission.
This permission is only in this version.

Related

How do I get the total views for a Facebook pagepost via the Graph API v2.7?

I have been using the Facebook Graph API Explorer Version 2.7 to attempt getting the post_unique_impressions value for a Facebook Pagepost (i.e. the total number of unique views for a page post). Here is what I have tried:
curl -i -X GET \
"https://graph.facebook.com/v2.7/{page_id}_{post_id}/insights/post_impressions_unique?access_token={token}"
Response:
{
"data": [
],
"paging": {
"previous": "https://graph.facebook.com/v2.7/{page_id}_{post_id}/insights/post_impressions?access_token={access_token}&debug=all&format=json&method=get&pretty=0&suppress_http_code=1&since=1473462734&until=1473721934",
"next": "https://graph.facebook.com/v2.7/{page_id}_{post_id}/insights/post_impressions?access_token={access_token}&debug=all&format=json&method=get&pretty=0&suppress_http_code=1&since=1473981134&until=1474240334"
}
}
The data in the response is just an empty array, I would expect to either see a view count or to see some kind of error message. What do I need to do to get the unique impressions for a page post?
Documentation: https://developers.facebook.com/docs/graph-api/reference/v2.7/insights
After some research, I found the solution. Facebook Insights requires that your page have 30+ likes in order to generate insight data. I was using a throwaway Facebook page with no likes, so no Insights data was being generated. It's a little confusing since there's no error message in the API response, just an empty array of data.
See: https://developers.facebook.com/docs/graph-api/reference/v2.7/insights

Facebook Api v2.2 - get album's photos shares count

I'm using the following Graph Api query in order to receive the likes and comments counts on all the photos in an Album inside my page:
https://graph.facebook.com/v2.2/album_id?fields=photos.limit(250){likes.limit(1),comments.limit(1),id,source},likes.limit(1)&access_token=my_access_token
I want to to also receive each one of these pictures shares count, but the share count is not connected to the photo end point, Its connected to the page_story_id.
So, in order to receive all the shares count i'm going to need to query each of those individually, which doesn't make sense when you have an album with 200 pictures (not to mention an album with 500 pictures).
FQL is deprecated after v2.1 so I can't use the FQL to get this (which will defiantly ease everything for me).
Isn't there an easier way to do so?
Update
Thanks to #CBroe comments, this is my batch:
[
{
"method":"GET",
"name":"get-photos",
"relative_url":"951337131548012?fields=photos.limit(250){likes.limit(1),comments.limit(1),id,source,page_story_id},likes.limit(1)"
},
{
"method":"GET",
"relative_url":"/?ids={result=get-photos:$.photos.data.*.page_story_id}"
}
]
Now it does return all the photos post objects, but how can I query them all the specific field? like add ?fields=shares
ok after struggling with this for few hours, and thank to #CBroe help I found the right batch request for my needs and it involves both batch and Graph API multiple requests.
[
{
"method":"GET",
"name":"get-photos",
"relative_url":"951337131548012?fields=photos.limit(250){likes.limit(1),comments.limit(1),id,source,page_story_id},likes.limit(1)"
},
{
"method":"GET",
"relative_url":"/?ids={result=get-photos:$.photos.data.*.page_story_id}&fields=shares"
}
]
by adding &fields=shares i'm filtering the fields of inner results of the multi request.
Hope it helps someone :)

Facebook graph API 'friends' request now only returning 25 friends per page? What's going on?

My application(game) has been running on Facebook for some time. I start by requesting a friends list via the graph API call: my-uid/friends
asking for user name and profile pic.
Normally I get back a list of all my friends up to a few thousand, until it starts putting friends on to the next page. Which is nice as most of my users get friends in 1 call.
Suddenly however, and with no changes to the app. about 40 minutes ago (18:40 Tuesday (PDT) - 2nd May 2012) I started getting responses with only 25 friends per 'page'!
I can still get my whole friends list using multiple calls, but the game is not currently set up to do that properly. Can anyone tell me why the sudden change? Anyone else seen similar problems and how do I get the list to give me up to 5000 friends per page like it used to.
Reproducible using the Graph API Explorer
I don't know what else to tell you; perhaps the default number returned has changed, but when I try, a call to /me/friends?limit=5000 returns the full list for me (but my friends list is >500 and < 1000 , so maybe it cuts off somewhere along the way)
(Side note: the average number of friends has been found to be ~190 so presumably most users will have less than 500 anyway, and having to page above 500 would be an edge case
In SDK 4.7 you need to pass in a bundle with the number of friends you want to return, I have set it to 5000 as this is the maximum number of friends you can have on Facebook.
You also need to set up your app as a game in the facebook dev console and use invitable friends to get a full friends list
Create your bundle
Bundle bundle = new Bundle();
Add params to your bundle
bundle.putInt("limit", 5000);
Then pass it in to your GraphRequest
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me/invitable_friends",
bundle,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
//Do something with the response
}
}
).executeAsync();
It seems that facebook changed its limit to 25 results in other api calls too (feed, posts, friends, etc), if you request friends without parameters the JSON response shows the following:
"paging": {
"next": "https://graph.facebook.com/USER_ID/friends?format=json&limit=25&offset=25&__after_id=LAST_ID"
}
Anyway you could/should always set limit & offset parameters to prevent this kind of things, limit = 0 will return all your friends list.
https://graph.facebook.com/USER_ID/friends?limit=0
If you are only requesting friends from a normal user the maximum number allowed is 5,000 so the limit should could be either 0 or 5,000 if you are requesting info from a facebook page or other kind of api calls like posts or feed this limit could increase or decrease.
(Update) Facebook fixed this bug so setting limit to 0 returns 0 friends, you should set a positive limit, thanks Dinuz
I think the best thing you can do is to add limit=5000 parameter as Igy says.
However I posted a bug report since this change wasn't noticed or described in the document.
The number of results returned from the /v2.2/me/friends endpoint now defaults to 25.
Friend list now only returns friends who also use your app: The list of friends returned via the /me/friends endpoint is now limited to the list of friends that have authorized your app.
See Facebook changes
Facebook API change log
If you are using GraphRequest() (e.g. in React Native), you can put it directly in the string field, like so :
new GraphRequest(
'/me',
{
accessToken,
parameters: {
fields: {
string: 'id,email,first_name,last_name,friends.limit(5000)'
}
}
...

Can't access news.reads actions using facebook open graph api

I have a facebook account I KNOW has articles posted to the open graph as read actions under the news.reads global namespace (I can see them under the News aggregation in my timeline) but when I try to get a list of them using this api address:
https://graph.facebook.com/me/news.reads?access_token=[my access token]
it returns:
{
"data": [
],
"paging": {
"next": "https://graph.facebook.com/me/news.reads?access_token=[my access token]&offset=25&limit=25"
}
}
as though there were no articles posted at all. I checked my permissions and cant find anything that might be causing this issue. Anyone know how I should be accessing this data correctly? Thanks!
You need the user_actions.news Permission in order to access the user's list of news reads, otherwise the array comes back empty

Why do I get this error when I try to access a certain type of object via the Facebook Graph API?

I have a user, user_2. There is a post on their wall, made by user_1.
The URL is
https://www.facebook.com/user_1/posts/10150166228506188
I try to get the content using the Graph API, with this request:
https://graph.facebook.com/10150166228506188?access_token=ACCESSTOKENUSER_2
I get this error:
{
"error": {
"type": "GraphMethodException",
"message": "Unsupported get request."
}
}
The access_token I am using is good, because requests to get things like statuses & images work fine:
https://graph.facebook.com/10150233707783933?access_token=ACCESSTOKENUSER_2
Result:
{
"id": "10150233707783933",
"from": {
"name": "American Steel",
"category": "Professional sports team",
"id": "203692078932"
},
"tags": {
"data": [
etc
The error seems to happen whenever I try to get items that have this kind of URL:
https://www.facebook.com/username/posts/item_id
The permissions my app has include these:
Why is this error occurring?
I think that, in order to access the posts directly through the graph api, you have to prepend the user id to the post id you see in the facebook url.
So in your example the facebook post url is :
https://www.facebook.com/user_1/posts/10150166228506188
And you try to get through the graph api :
https://graph.facebook.com/10150166228506188?access_token=ACCESSTOKENUSER_2
BUT you should be doing :
https://graph.facebook.com/{id of user_1}_10150166228506188?access_token=ACCESSTOKENUSER_2
I noticed that all posts ids are formed like this by visiting :
https://graph.facebook.com/me/posts?access_token=...
Does this solve your problem ?
You're accessing the end-point of the post incorrectly. Every object on Facebook has a unique ID. Right now, it just so happens that they form it by appending different IDs together (your post is an example, <user_id>_<post_id>, and for a comment on that post it'd be <user_id>_<post_id>_<comment_id>). Facebook hasn't made public acknowledgment of this (not that they really have to, it's obvious) which makes me leary to rely on that paradigm for accessing data within the graph. This is because Facebook could change it at any point, and the fact that they haven't said "yeah append these 2 ids together and you can get something meaningful from this part of the graph" means they won't have to notify anyone about the change, you could just wake up one day and your app be completely broken and you'd have to find a work around quickly and while suffering down time.
The graph api works by accessing objects on Facebook by making a request to the API for that unique ID. So, you don't need to access (and can't access) your posts by going to graph.facebook.com/<user_id>/posts/<post_id>. Instead, you go to graph.facebook.com/<post_id>. You get the post_id from the /<user_id>/home or /<user_id>/feed end-point on the graph. There is no need to modify a post_id in order to fetch information about it from the graph.
Hope that helps