Saturday, June 6, 2020

How to get the Access Token for Facebook Graph API?

In this How to pull the hashtags from the FeedBurner post, we have extracted the hashtags that we are going to post on the Facebook page, and in this post, we need to generate an access token for Facebook Graph API. Please follow the instructions to get started with it:

How to get the Access Token for Facebook Graph API?

  1. Go to Facebook Graph API Explorer and Click on Login  
  2. Create a new app or continue with the already created app. 
  3. On the right side, you should see the newly created Facebook App, if you want to work with a different app, you can switch the apps by choosing from the dropdown list. In my case, I want to work with Especiallysports app.  
  4. Next to Facebook App, you can find an option that says, User or Page, this option lets us choose whether we want to work with User profile, page profile, particular App. Please note, the tokens are issues at different levels, user level, page level, app level.  In my case, I would like to work with pages, I'll choose the Get Page Access Token. When you select the above option, a dialog box appears asking for the consent. Just click on the continue and provide the necessary page access and required permissions for that. 
  5. Once step 4 is completed, you'll find the pages in the dropdown list where you can able to choose the page that you want to work with. In my case, I want to work with Especiallysports page, therefore, I have chosen that. 
  6. Just below User or Page option, you can find add permissions option, which lets you can add additional permissions.  
  7. Click on Generate Access Token and copy the token 
Now, its time to test if we have access to our Facebook data. On the left side, you see an option where you can see and perform operations such as GET, POST, DELETE. Let's get started with getting the data. 

When you click on the submit button, you should see the id and name of the page. 
Testing Facebook Graph API

To retrieve the page posts, you can change URL to me/posts

To retrieve a specific page post, you can change URL to /Postid, as shown in the below URL.

To publish a post on the Facebook page, you can use below, A Facebook page post will be created on the Facebook page. You can refer to the below screenshot:

Here is the screenshot of the Facebook page post.

To delete this post, you can use DELETE operations when the post is deleted, it returns success message as shown in the below screenshot.

In the next article, you can learn how to connect programmatically and perform various operations such as retrieving, publishing, and deleting the posts using Python script.