This tutorial shows you how to use the Video API to create a Video on a Page. It assumes you know how to perform basic cURL requests with a command-line tool like Terminal, or an app such as Postman, and have basic familiarity with the Graph API Explorer.
You will need:
CREATE_CONTENT
Tasks on.As a general practice, you have to implement Facebook Login into your app and use it to get Access Tokens from your app users. However, for this tutorial, you can use the Graph API Explorer because it has already implemented Facebook Login and makes it easy for you to generate tokens for any of your apps.
pages_manage_engagement
and pages_read_user_content
.
GET /me/accounts
edge.
This queries your user and returns any Pages that you authorized your app to access in the last step. id
) and Page access token (access_token
).{ "data": [ { "access_token": "EBACf...", //Copy your Page Access Token "category": "Media", "category_list": [ { "id": "163003840417682", "name": "Media" } ], "name": "Metricsaurus", "id": "1755847768034402", //Copy your Page ID "tasks": [ "ANALYZE", "ADVERTISE", "MODERATE", "CREATE_CONTENT", "MANAGE" ] } ], "paging": { "cursors": { "before": "MTc1NTg0Nzc2ODAzNDQwMgZDZD", "after": "MTc1NTg0Nzc2ODAzNDQwMgZDZD" } } }
POST /page-id/videos
edge on the graph-video.facebook.com
host. If you are using Postman, include the query parameter keys and values in the request Body as form-data.curl -X POST \ "https://graph-video.facebook.com/1755847768034402/videos" \ -F "access_token=EBACf..." \ -F "upload_phase=start" \ -F "file_size=77188035"
1755847768034402
) in the request path with your Page's ID, set access_token
to the Page access token you just copied, and file_size
to the video file’s total size, in bytes.{ "video_id": "225467151853466", "start_offset": "0", "end_offset": "1048576", "upload_session_id": "225467155186799" }
end_offset
.Send another request to the POST /{page-id}/videos
edge and include your upload_session_id
and the name of your first video chunk.
curl -X POST \ "https://graph-video.facebook.com/1755847768034402/videos" \ -F "access_token=EBACf..." \ -F "upload_phase=transfer" \ -F "start_offset=0" \ -F "upload_session_id=225467155186799" \ -F "video_file_chunk=@xaa"
If you are using cURL, include the @
symbol before your file name.
If you are using Postman, omit the @
symbol, set video_file_chunk
to File (hover over the row to trigger the drop-down menu) and manually select the first chunk file.
The API will respond with a new start_offset
. Capture the new value.
{ "start_offset": "10485760", "end_offset": "15728640" }
start_offset
to the new start_offset
value returned in the previous response, and set video_file_chunk
to the name of the next video chunk in sequence.curl -X POST \ "https://graph-video.facebook.com/1755847768034402/videos" \ -F "access_token=EBACf..." \ -F "upload_phase=transfer" \ -F "start_offset=10485760" \ -F "upload_session_id=225467155186799" \ -F "video_file_chunk=@xab"The API will once again respond with a new
start_offset
value, which you can use to upload the next chunk in sequence.
{ "start_offset":"15728640", "end_offset":"20971520" }
Once you have uploaded your final chunk, end the upload session by sending one final request to the same endpoint and set upload_phase
to finish.
curl -X POST \ "https://graph-video.facebook.com/1755847768034402/videos" \ -F "access_token=EBACf..." \ -F "upload_phase=finish" \ -F "upload_session_id=225467155186799"
Upon success, the API will end the upload session and respond with true
.
{ "success": true }
We will assemble your video and encode it. The encoding process may take up to several minutes to fully encode, depending on the total size of your video file.