Post status message & Images on Facebook using Graph API & C# – Part I

Realizing the importance of social media, in the previous blog we learned to integrate twitter to our C#.Net application. We saw “How to post message and image on Twitter”. Now let’s learn how to post messages & images on Facebook account as well as Facebook Page.

How to use to post messages and Images on Facebook Account & Page using ASP.Net C#

For integrating Facebook to your application we need to generate the keys & access token to authenticate the application.

Generate keys & access token

1. Sign In at “https://www.facebook.com” using your Facebook login id.

2. After that browse to the “https://developers.facebook.com” page.

Register as a Developer
Register as a Developer

3. Accept it by selecting the option to “YES” in the dialog box opened.

Accept the Facebook Platform Policy
Accept the Facebook Platform/Private Policy

4. After clicking on Register you will get this screen, click on “Done” to continue.

Get Confirmation After Registration
Get Confirmation After Registration

 

5. After clicking “Done” you will be redirected to this screen, you can develop the app which will be integrated to Facebook. Select the type to app you want to develop.

Add A New App
Add A New App

6. I have used the website as I will be connecting to web app. Create new app as shown in the image.

Create Facebook App ID
Create Facebook App ID

7. After clicking on “Create New Facebook App ID”, you will get below screen where you have to select the category of your application.

Choose Category Of Application
Choose Category Of Application

 

8. After creating App ID, you will get the SDK script as shown below which can be used on page load.

Facebook SDK for Javascript
Facebook SDK for Javascript

9. After clicking on “Skip Quick Start”, you will be redirected to dashboard.

App Dashboard
App Dashboard

10. Go to “Tools & Support” menu to retrieve Access Token.

Tool & Support Menu
Tool & Support Menu

 

11. Here you will get the User & Application access tokens of you apps created.

User & App Access Token
User & App Access Token

 

12. Click on “need to grant permission” to assign permission to your application and retrieve user access token.

Access Token Creation Confirmation
Access Token Creation Confirmation

13. You will get the User access token here and you can debug and check if it’s working or expired as shown below.

Debug User & App Access Token
Debug User & App Access Token

14. After clicking debug beside “User Token” you will get the access token information as shown below.

Access Token Debugger & Info
Access Token Debugger & Info

15. After clicking debug beside “App Token” you will get App token & its id with name as shown below.

Access Token Debugger & Info
Access Token Debugger & Info

16. Go To “Graph Api Explorer” menu from “Tools & Support” menu and you will get the below screen from which you can user access token & debug it to check if it is valid as well as you can get data, post data or delete the data.

Graph API Explorer
Graph API Explorer

17. You can select the Account/Page from “Get Token” drop down to retrieve its user access token(For first time it will only show Get Access Token and Page Access Token as shown below) you can click here and retrieve the access token.

Get Access Token
Get Access Token

 

18. Assign user data permissions and extended permissions as shown below.

User Data Permissions
User Data Permissions

Extended Permissions
Extended Permissions

19. After clicking get access token you will get the below screen. Click okay and you will get the user access token.

Graph API Explorer Authorities confirmation
Graph API Explorer Authorities confirmation

20. Copy the access token and you can use this in your application.

Access Token
Access Token

21. Retrieve album id as this will help to retrieve album information as well as you can post photos into this album with the help of this id.

Get Album ID Using Graph API
Get Album ID Using Graph API

 

22. Retrieve the account/page id as well as album id of that account/page.

  • Select you page
Choose Facebook Account/Page
Choose Facebook Account/Page

  • Retrieve the page id
Account/Page ID
Account/Page ID

  • Retrieve the desired album id from the page so that you can post photos into that album
Get Album ID Using Graph API
Get Album ID Using Graph API

Refer the next blog for the code to post message, images and albums on Facebook using above keys access tokens and id’s.

 

Leave a comment