I'm attempting to fetch all photos and videos from a Facebook event using the Facebook Graph API.
Currently I'm using the /{event-id}/feed
endpoint, described here https://developers.facebook.com/docs/graph-api/reference/v2.6/event/feed
I can get almost everything I need from this endpoint by specifying the fields I want, but I'm having trouble getting URL to the the videos in full resolution. I can easily get them by making another API call, but I want to avoid making another API call for all videos, if possible.
Please note that the /{event-id}/feed
endpoint returns an array of Post objects
, which is what I'm querying using the fields
query parameter.
https://developers.facebook.com/docs/graph-api/reference/v2.6/post
Here's the fields I´m specifying when calling the /{event-id}/feed
endpoint
https://graph.facebook.com/v2.6/{event-id}/feed?fields=attachments,id,created_time,caption,from,name,message,message_tags,source,type,status_type,properties,object_id,picture&access_token={access-token}
The attachments
field gives me image URL of the video in high resolution and the ID of the video itself. This means that I need to make additional API call just to get the video URL in high resolution using the /{video-id}
endpoint.
"attachments": {
"data": [
{
"media": {
"image": {
"height": 405,
"src": "https://scontent.xx.fbcdn.net/v/t15.0-10/s720x720/13433040_10154318390596912_1315696369_n.jpg?oh=46987fa671df2deca3ce935a68e1ff30&oe=58008D60",
"width": 720
}
},
"target": {
"id": "10154318389716912",
"url": "https://www.facebook.com/{username-removed}/videos/10154318389716912/"
},
"type": "video_autoplay",
"url": "https://www.facebook.com/{username-removed}/videos/10154318389716912/"
}
]
}
The source
field gives me link to the video in low resolution.
"source": "https://video.xx.fbcdn.net/v/t42.1790-2/13543016_152852391800500_1248221173_n.mp4?efg=eyJybHIiOjMxMywicmxhIjo1MTIsInZlbmNvZGVfdGFnIjoic3ZlX3NkIn0\u00253D&rl=313&vabr=174&oh=f0f42856741b81030ea529fe89f80834&oe=5771B45B"
The object_id
field gives me the video ID.
The properties
field gives me the length of the video.
So I'm out of luck. I'm wondering if it's possible to make some nested call that would give me the URL of the high resolution video, or if I could call some endpoint with the video ID that returns 302 redirect to the video. Could I maybe modify the parameters to the source URL?
Any help is much appreciated. Thanks!
"...I'm wondering if it's possible to make some nested call that would give me the URL of the high resolution video..."
Solution :
To make all the API calls you want at once, you can try Batch Requests with Graph API.
See the documentation & examples at : Facebook API - Making Multiple Requests
Quote from the Docs :
" ... Batching allows you to pass instructions for several operations in a single HTTP request. You can also specify dependencies between related operations (described in a section below). Facebook will process each of your independent operations in parallel and will process your dependent operations sequentially. Once all operations have been completed, a consolidated response will be passed back to you and the HTTP connection will be closed."
As you can see, it is to make multiple requests and create dependencies between them.
So when you get the video_id
you're able request the video right there in the resolution you want.