2016年6月6日星期一

[Go live with Facebook Live API] Step 3: For professional API developer

If you are a professional api developer, there are also something you might interested in:

Besides creation, the public API supports full CRUD functionalities. You can also

Read the metadata of a live video

  • Via Graph API Explorer


  • Via Curl
 curl -k -X GET https://graph.facebook.com/$live_video_id -F "access_token=$your_user_or_page_token"  

Update the metadata of a live video

  • Via Graph API Explorer


  • Via Curl
 curl -k -X POST https://graph.facebook.com/$live_video_id -F "access_token=$your_user_or_page_token"  

Delete a live video

  • Via Graph API Explorer

  • Via Curl
 curl -k -X DELETE https://graph.facebook.com/$live_video_id   
 -F "access_token=$your_user_or_page_token"  

enumerate live videos of a profile

  • Via Graph API Explore

  • Via Curl
 curl -k -X GET https://graph.facebook.com/$user_or_page_id/live_videos -F "access_token=$your_user_or_page_token"  

Beside those, please access the official documentation for different parameter usage: https://developers.facebook.com/docs/graph-api/reference/live-video/


[Go live with Facebook Live API] Step 2: Create a live video and stream it

After previous blog, I believe you already have your app ready with the right permission setting.

There are two ways to create a live video in facebook. Let's go through an example here. I want to create a live video on my profile timeline.


     Note, in the url,  I use /me/ to represent myself. If you want to create a live video on a page/group/event, you need to use page/group/event id here.
  • user command line 
 curl -k -X POST https://graph.facebook.com/$your_userid_or_pageid/live_videos  
 -F "access_token=$your_user_or_page_token"  


And you will receive the stream_url as the rtmp ingestion endpoint for your encoder, for example:
     rtmp url        rtmp://rtmp-dev.facebook.com:80/rtmp/ (http://rtmp-dev.facebook.com/rtmp/)  
     key           10207831706528497?a=Adoap6R3g0o3Jd96o4k   


With this ingestion url, you can use any 3rd part encoder to stream the content. If this is your first time broadcasting, please install this software (https://obsproject.com/download#mac) and follow the guide here: https://www.youtube.com/watch?v=23RErS0H9gY

Make sure you input the steam_url and key in the right format as below:


Click the "Start Streaming" button, and switch to your facebook. You will see a similar post as below



















[Go live with Facebook Live API] Step 1: Register your app and set permission

In order to play with Facebook Live API,  you need to have a app first. It's free to register here: https://developers.facebook.com/apps/


Note: your test app must be in “publish” mode. If the app is in 'dev' mode, the post can only be seen by the app admins even you set the privacy as 'public'. You can do following things to get your test app out of 'dev' mode:

  1. Go to your app setting tab, add your contact email there
  2. Then go to the app review tab, flip the toggle at the top to take it out of development mode

After you have your app ready, you can come to Graph API Explorer: https://developers.facebook.com/tools/explorer/ and configure your app permission there.
  • Set 'Application' to your app or our test app.


  • Grant permission by clicking the 'Get Token' button. If you are posting to your timeline, select “Get Access Token” with only 'user_videos' selected
  • If you are posting to your page, select “Get Page Access Token” and also select 'manage_pages' and 'publish_pages'.

  • If you are posting to group, select group permission also


 Then in the pop-up window, click OK to authorize the APP.




Setup your app and permission well. You can play with Live API now.