I'm using the Facebook Graph API in an app that plays the videos in an event's feed. I need to get the MP4 stream URL to play it in my UI. Some videos appear as top-level posts in the feed, and the source property is exactly the URL I need - yay! Others appear as attachments (or subattachments within an album). For these, the attachment.url
(and the attachment.target.url
) point to an HTML page, not the MP4 stream. For example, getting this particular post with the attachment field results in:
{
"attachments": {
"data": [
{
"media": {
"image": {
"height": 405,
"src": "https://scontent.xx.fbcdn.net/v/t15.0-10/s720x720/16327151_10154408614623022_6300713295200387072_n.jpg?oh=9b3b65b957e0a3b8fe4fa1429bf49d1c&oe=58FE6EE2",
"width": 720
}
},
"target": {
"url": "https://www.facebook.com/fmyman/videos/10154408612948022/"
},
"type": "video_autoplay",
"url": "https://www.facebook.com/fmyman/videos/10154408612948022/"
}
]
},
"id": "1851001951851194_1852406911710698"
}
Alas, there's no MP4 stream URL, nor is there a node ID that I can use to fetch the video node.
My next hope was that the string of digits in the URL was the ID for the video node. Trying that, Facebook responds with an error message, saying that the digit string is not a valid node ID.
{
"error": {
"message": "Unsupported get request. Object with ID '10154408612948022' 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": "BMqL5viB2je"
}
}
My final attempt was to fetch the given URL and find a video node ID somewhere within it. Again, no luck. The URL points to an HTML page, but there's nothing obvious there that might be the video ID or MP4 stream URL.
So here I am, at my wits' end, hoping someone has solved this problem: How can I get the MP4 stream URL from a feed post attachment?
It turns out that the digit string in the URL is indeed the video node ID. I had interpreted the error message as indicating that it wasn't, whereas what it means is that I didn't have permission to access that particular video node (e.g. if the video creator configured their account to disallow Facebook Platform access).
To specifically answer my question:
attachment.url
value, e.g. "https://www.facebook.com/fmyman/videos/10154408612948022/".source
field.source
field is the URL of the MP4 stream.var url = 'https://graph.facebook.com/' + video_id + '?fields=source&access_token=' + access_token
IMPORTANT
the video source can ONLY be accessed
https://developers.facebook.com/docs/graph-api/reference/video/