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

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

Related

How to get Instagram post URL from Facebook Graph media_id

I'm using Instagram Mentions API and was able to obtain FB media_id for couple Instagram posts.
I need media_id to get post content via /user/mentioned_media. Unfortunately that endpoint does not provide ig_id or shortcode or permalink which I need.
Is there a way to get Instagram Post URL with FB Graph API media_id?
It seems like you can get media metadata (and all comments/replies) when someone #-mentions you in a non-owned-media comment by using a query like below.
You would use your own instagram business account id for the first number (the path component), and you'd use the comment_id you received from the webhook comment-mention notification as the second number:
/12345678901234567890?fields=mentioned_comment.comment_id(9876543210987654321){id,text,username,timestamp,media{id,media_type,media_url,permalink,username,like_count,comments_count,comments{id,text,username,user{id,username},like_count,timestamp,replies{id,text,username,user{id,username},like_count,timestamp}}}}
Yes, there is a way you can get Instagram post URL associated with a media if you know the media id.
You can also get more information (all its fields and edges) on media. See the docs here
You can get the Instagram post URL by making a GET request to /{ig-media-id}
Sample Request:
GET https://graph.facebook.com/v15.0/{{media_id}}?fields=permalink, shortcode&access_token={{ACCESS_TOKEN}}
Sample Response:
{
"permalink": "https://www.instagram.com/p/Clxsi5Pol2_/",
"shortcode": "Clxsi5Pol2_",
"id": "17xxx59557977xxx"
}
The value of the permalink is the valid public URL for the post.
You can also use the shortcode returned to construct the URL by concatenating the shortcode to https://www.instagram.com/p/.

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.

Error with Twitter link

Yesterday I started a new app on Facebook. Today I got the message that when people copy the link to Twitter they get an error. This is what you get:
{
"error": {
"message": "Unknown path components: /your_namespace:your_action",
"type": "OAuthException",
"code": 2500
}
}
What does this mean? What could be the problem?
Are you actually sending the POST action link to Twitter? Why?
I think you misunderstood how Open Graph works. Basically, you should be the one publishing actions when users take an action using your service. You can use a server-side or a client-side language to POST request (when you click a link, your browser actually makes a GET request, not a POST) to https://graph.facebook.com/me/namespace:action?access_token=ACCESS_TOKEN&OBJECT_PATH=OBJECT_URL
Note that you need to create an app, use it to authenticate users to get the access token and also set your custom actions / objects. These will need to be approved before you can actually use them.
You should start by taking a look at the sample apps to see how they work: https://developers.facebook.com/docs/samples/

Facebook Graph API does not return the event picture

Edit: Seems like Facebook finally fixed this bug!
Could you help me understand why this is happening:
This is a public event with a picture:
https://www.facebook.com/events/282054218538223
But when I try to access http://graph.facebook.com/282054218538223/picture, all I get is a default picture.
Here is another public event: http://www.facebook.com/events/266496120103339
But this time, accessing http://graph.facebook.com/266496120103339/picture returns the event photo.
What's the difference between the 2 events?
This answer doesn't explain why the request doesn't work using Graph API but might help someone who needs to to retrieve event profile images.
With FQL you can retrieve the event profile image like this:
SELECT pic, pic_small, pic_big FROM event WHERE eid=282054218538223
using the event id from Robin's first example. This call returns urls to the event profile image in 3 different sizes. It works for both examples in Robin's question, just change the event id.
Try it in Graph Explorer with Robin's example:
https://graph.facebook.com/fql?q=SELECT pic,pic_big,pic_small FROM event WHERE eid=282054218538223
and MoXplod's example:
https://graph.facebook.com/fql?q=SELECT pic,pic_big,pic_small FROM event WHERE eid=271148229633674
Make sure you have access token if needed as outlined in the FQL event table.
having the same problem. it appears to indeed be a bug with the Facebook Graph API.
I currently count at least three separate open bug-reports on the Facebook Developers Bugs page that describe and reproduce the problem (you may need to be logged into FB to access the information) :
Cannot retreive picture of newly created events via Graph API
Some event covers not available via Graph API
Event picture is not accessible via API
fwiw, it might be a good idea to subscribe to all three (duplicate) bug-reports.
I was fighting with this problem this evening. The docs are saying to use picture but what I found exploring fields is this one:
{event-id}/?fields=cover
which finally returns:
{
"cover": {
"offset_x": 99,
"offset_y": 50,
"source": "{url}",
"id": "{id}"
},
"id": "{id}"
}

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