1. Create a Facebook ‘App’:
Firstly you need to create a Facebook App, which is required in order to use the API. Sign in to your Facebook Developers account and click the ‘Add a New App’ link as shown below:https://developers.facebook.com/
Enter your App name and click ‘create’. Under ‘settings’, you’ll need to add a ‘website platform’ and enter the domain where this script will sit. For security, it’s also worth adding the IP address of the server where your site sits in the ‘Server IP Whitelist’ field. You do so under ‘advanced settings’.
2.Get a non-expiring Access Token for your App:
Next up, if you want to automatically post content to your Facebook page like I needed to…you’re going to need to get a non-expiring Access Token for your page. Firstly, visit the Facebook Graph API Explorer page. You’ll see an ‘Application’ button in the top right as show below:
As you can see, currently this is set to ‘Graph API Explorer’. Select your Facebook App instead. Now click the ‘get token’ button which you can also see in the image above. Select ‘Get User Access Token’ and make sure the ’publish_pages’, ‘manage_pages’ or ‘publish_actions’ permissions are ticked, then click the ‘Get Access Token’ button. Now click the ‘get token’ button again and select your Facebook page. You now have your Access Token which we need to convert into the non-expiring Access Token. To do so, pass your App ID, App Secret and Access Token into the following URL:
Now copy the token provided. And enter into register/profile page.
Note: You will see the post appear on the Facebook page, but no-one else will as you have not set your App ‘live’! To do so, go back to your Facebook Developers account and select your App. Under the ‘Status & Review’ tab tick the checkbox at the top of the page next to the text ‘Do you want to make this app and all its live features available to the general public?’.