Understanding The Facebook Live Through Facebook Graph API
Posted By : Arun Singh | 29-Apr-2018
First, you have to create facebook app account if you did not create follow this link
1) Go to My Apps.
2) Click "+ Add a New App".
3) Setup a website app
Don't need any changes its permissions or anything. We have to need an app use for facebook graph API through access token.
->Step for getting user short-lived access token
1) Go to the Graph API Explorer link here.
2) Select the application you want to get the access token for (in the "Application" drop-down menu, not the "My Apps" menu).
3) Click "Get Token" -> "Get User Access Token".
4) In the pop-up, under the "Extended Permissions" tab, check "manage_pages".
5) Click "Get Access Token".
-->Url for getting your facebook live videos which you post.
https://graph.facebook.com/v2.12/me?fields=live_videos&access_token={facebook login token}
-->Url for getting reactions, likes, comment of the particular video
https://graph.facebook.com/v2.12/{video-id}?fields=reactions,likes,title,comments
Now I will elaborate the access tokens and OAuth 2.0 to make the concepts clear.
OAuth 2.0
1. The standard OAuth 2.0 implementation, the first step is to invoke the OAuth Dialog of the service provider (facebook)-
\GET http://www.facebook.com/dialog/oauth
Parameters:
client_id (APP ID)
redirect_uri (App's Redirect Url)
scope (permissions - optional)
Returns:-
code (appended with the redirect url)
2. When user successfully authenticated the app, a code is returned by the service provider(facebook) appended with the redirect_url passed. So you'll be redirected to-
{redirect-url}?code=XXXXXXXXXXXXXXXXX
We use this code then and request for the access_token-
\GET https://graph.facebook.com/oauth/access_token
Parameters:
client_id (APP ID)
client_secret (APP Secret)
code
redirect_uri
If you dont need to build this manual flow, you can use the SDKs. It will just application to the outh dialog and if success will give you the access token in response.Facebook provides official SDKs for iOS, Android, Javascript and PHP; also there are other third-party SDKs.
Access Tokens
There are 3 types of access tokens to support different use cases:
User Access Token:-
This type of user-access token is required any time the app calls an API to read and modify or write a specific person's Facebook data on their behalf.
App Access Token:-
This access tokens are used to makes requests to Facebook APIs on behalf of an app. With this access token we can create, and manage test users, or read your application's insights.
GET /oauth/access_token?
client_id={app-id}
&client_secret={app-secret}
&grant_type=client_credentials
or directly from here, or simply use {app-id}|{app-secret}
/GET /{page-id}?fields=access_token
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Arun Singh
Arun is a MEAN stack developer. He has a fastest and efficient way of problem solving techniques. He is very good in JavaScript and also have a little bit knowledge of Java and Python.