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

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

Related

How to display "from" fields in comments via Facebook Graph API

I would like to find the id (app-scoped) for someone who has posted a comment on a public page.
For example, I get a list of recent posts/comments on the NY Times page via:
v2.11/nytimes/feed?fields=comments.limit(10){message,created_time,from},name,message,from&limit=2
The data returned looks like this:
"comments": {
"data": [
{
"message": "Wouldn’t know. Not paying $13/mo for this.",
"created_time": "2017-12-10T05:57:18+0000",
"id": "10151412260164999_10151414049324999"
}
],
There is no from field. The same is also true if I attempt to view the comment directly using it's id with
v2.11/10151412260164999_10151414049324999?fields=from,message,created_time
I have tried using the Facebook Graph API Explorer, using both my User Token, as well as an App Token.
Since v2.11 of the Graph API, you need a Page Token to get user data of comments: https://developers.facebook.com/docs/graph-api/changelog/version2.11#gapi-90
User information will not be included in GET responses for any objects owned by (on) a Page unless the request is made with a Page access token. This affects all nodes and edges that return data for objects owned by a Page.
In other words: You can only get user information if you manage the Page.
Edit: Since the latests update in the Graph API, you have to get the App reviewed and you must go through Business Verification or Individual Verification. (thanx #Guiman04)
Please check whether you are using the accessToken for the page you are trying to get data from, i had same issue, and was resolved by using the correct accessToken for the page.

How to obtain the live video id of a facebook live video?

I am trying to access the live views count of a live video that is live through a Facebook Page. I am using the ID that I am obtaining from the API request {page-id}/videos/uploaded When I am using that video id and making a GET request of {video-id}?fields='live_views its showing error code of 100 with the message as:
(#100) Tried accessing nonexisting field (live_views) on node type (Video)
I have the following permissions:
'manage_pages', 'publish_pages', 'business_management', 'read_insights', 'user_videos'
I am making the GET request using user_access_token.
I am using Graph API Version 2.8.
Please let me know if I am using the wrong ID. IF yes, then how can i get the live_video_id of a live video posted in page?
To get the live views count of a video a fan page, you need:
An app created at facebook developer
A user access token (for testing, e.g. by calling https://developers.facebook.com/tools/accesstoken/)
The fan page id
With this you can call graph API in the following format:
https://graph.facebook.com/v2.8/<fan_page_id>/live_videos?access_token=<access_token>?fields=live_views
Of course, you may add more elements in fields parameter if you need more information. Here Facebook's Graph API explorer helps: https://developers.facebook.com/tools/explorer
When you add status to fields parameter, "LIVE" means, it's currently live, "VOD" means it has already finished.
If you try to implement a WebHook for it, let me now if it works. Thanks.
To get live views you need to call the api with the live video id, which you get from calling, page id can initially be either the page-id or name
"https://graph.facebook.com/v10.0/${page_id}/live_videos?access_token=${access_token}
Sample response:
{
"title": "hello world 2",
"status": "LIVE",
"embed_html": "...,
"id": "123123" // this is the live video id
},
After you have retrieved the live video id you can call this endpoint to get the live_views edge
https://graph.facebook.com/v10.0/${live_id}fields=live_views&access_token=${access_token}
sample response:
{
"live_views": 1,
"id": "123123"
}
Docs for endpoint 1: https://developers.facebook.com/docs/graph-api/reference/live-video/
Docs for endpoint 2: https://developers.facebook.com/docs/graph-api/reference/live-video/reactions#Reading
However I understand the confusion since live_views is not listed under the second endpoint as a reaction nor even is it a reaction, so either it a mistake in facebook docs or a mistake in the graph API, either the solution provided works.
Yes you do need to go through an app review to get the permission for tracking streams

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

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.

Graph API tells me an object doesn't exist while it does

I'm starting to create a little app to get the names associated with Facebook IDs for a bigger project. I just started to use the Facebook API and it's giving me weird results. Most of the time, everything works fine. I use this code (I'm using Python, but that doesn't really matter here since it's the Facebook API that is causing the problem) :
def downloadString(url, params):
cookie = {}
data = requests.get(url,cookies=cookie,params=params)
return data.text
url = "https://graph.facebook.com/v2.6/"
id = "afriendidhere"
dl = basics.downloadString(url + id, {"access_token":accesstoken})
res = json.loads(dl)
As I said, most of the time, it works just fine, giving me the name of the given person. Though, for two people in my friends list, I get the following message :
{
"error": {
"message": "Unsupported get request. Object with ID 'theid' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"fbtrace_id": "FTfrh78XjW/"
}
}
I don't understand why. The person with this id does exist, since I can access the page http://facebook.com/messages/theid and it's giving me my conversation history with this user. It's always the same people who cause the error, everyone else works perfecty.
Does anyone know why ?
You are only supposed to get data from users who authorized your App. Authorized them, get their App Scoped ID and name with the /me endpoint. More information: https://developers.facebook.com/docs/graph-api/reference/v2.6/user
The solution for me was to publish the page in settings
Page Visibility --> Publish
Save changes
Try removing any visibility limitations from your Page's settings (such as country restrictions etc)

Commenting on Facebook Page Ratings (Reviews) via Graph API

Long time lurker first time poster...
We are working with Facebooks API's to integrate into our web application and we are able to pull a Companies Page Rating via the {open_graph_story} parameter in the {page-id}/ratings section, however we cannot find a way to comment/reply to the rating. The documentation states:
"If a person has rated your page and a story has been generated, you can follow up with the person by posting to the story's comment node." (https://developers.facebook.com/docs/graph-api/reference/v2.0/page/ratings)
however when we pull the variables we retrieve no ID to reference for a comment. This is what we receive back from our authenticated account:
"data": [
{ "created_time": "2014-07-16T05:52:50+0000", "reviewer": { "id": "100000237096397", "name": "Romey Salazar" }, "rating": 5, "review_text": "Great job guys!!!!" } ],
Does anyone know how to retrieve the id for the rating itself so we can append a comment via API? Or some other way to reply/comment to a FB Page Rating?
Thanks!
When you have some ratings/review comments on your page and if you want to post comment to individual review comments as the Page Owner, you can follow the steps below.
1) Below request returns the json object of rating and reviews.
https://graph.facebook.com/v2.9/{YOUR_PAGE_ID}/ratings?field=open_graph_story&access_token={YOUR_PAGE_ACCESS_TOKEN}
The response json will contain ID field for each and every rating/review comments.
2) Using the ID, trigger the below request to post a comment on the rating as the Page Owner. You will need Page access token with manage_pages and publish_pages privilege.
https://graph.facebook.com/v2.9/{ID_OF_THE_RATING}/comments?message=Thanks for your rating&access_token={YOUR_PAGE_ACCESS_TOKEN}
These requests can be tested using Facebook Graph API Explorer
You need to request the open_graph_story field with the ratings endpoint. This will return the open_graph_story data which includes an id. You can then post to the comments endpoint of this story.
You have to make http get request on
https://graph.facebook.com/v2.9/{PageID}/ratings?fields=open_graph_story&access_token={PageAccessToken}
to get detailed response.
Make sure the parameter is "fields" not "field"