Auto Post on Facebook with PHP

category: Snippets
Created by: Dr.Ferrous

Auto Post on Facebook with PHP

category: Snippets
Created by: Dr.Ferrous
twitter google+ facebook pinned 

Step 1: Download Facebook PHP SDK

click here to download the Facebook PHP SDK

Step 2: Create a Facebook app

Sign in to your Facebook account and go to this link: https://developers.facebook.com/apps

If this is the first time you create an app, you'll see this:


Click on "Register now" and accept the Facebook Platform Policy and the Facebook Privacy Policy, then type you phone number for verification.

Once you click on "Send as Text", Facebook will send you an SMS containing a code, put that code in the text box "Confirmation code"

And hit Register, and you'll be redirected to quickstart url.

Click on WWW.

Type in your app name, for example "Roberto Carlos" and click on "Create New Facebook App ID" and then fill the required fields.

You'll be asked to put your website that will use the Facebook SDK.

Now go back to this link https://developers.facebook.com/apps/ and click on your app.

Go to App Review tap and turn on the switch button to make it public.

Go to the dashboard and copy App ID & App Secret and put them somewhere because you'll need them later.


Don't let anyone to know your App Secret.

Step 3: Authorize your app

Replace App_ID with your app's id and open it:


You'll be redirected to the redirect_uri which is (in this example) phpwin.org, and the address will be like this:

http://www.phpwin.org/?code=AQDLYoaBucZ5C23C9ReR... very long

copy the long code and put it in this url with app Secret & App ID then open it:


Now Copy your access token because you'll need it.

Step 4: Using the Facebook SDK

Now In order to publish a post in your page, you must get the pages's ID

Put your previously generated access token in this link and open it:


you'll see something like this:

copy the page's ID and put them in post.php

Extract Facebook SDK and create a php file, for example post.php


The Script:

This script will not work in this lesson, because there's no facebook.php in the site, use it in your own server.