Auto Post on Facebook Page using Facebook PHP API

Auto Post on Facebook Page using Facebook PHP API

Today, We want to share with you Auto Post on Facebook Page using Facebook PHP API.
In this post we will show you How to Auto Post on Facebook Using PHP, hear for Automatically Post Content To Facebook Using PHP we will give you demo and example for implement.
In this post, we will learn about Automatically post to a Facebook page using the Facebook PHP API (v5) with an example.

Step 1: Create a Facebook ‘App’ on Facebook Developers:

First Of all step We need to create a Latest a Facebook App, which is required in order to use the API. Login to your Facebook Developers account and Simple click the ‘Add a New App’ link as shown below Screen Shot:

Automatically post to a Facebook page using the Facebook PHP API 1
Automatically post to a Facebook page using the Facebook PHP API 1

Simple your App name and click to tap ‘create’. Under section Like as ‘settings’, We Will need to Simple Add a or selected‘website platform’ and enter the your domain name like as a ( where this script will take. For security, it’s also worth adding the IP address of the server where your site takes in the Simple ‘Server IP Whitelist’ Input field. We do so under The Options Like as ‘advanced settings’.

Automatically post to a Facebook page using the Facebook PHP API 2
Automatically post to a Facebook page using the Facebook PHP API 2

Step 2: Facebook PHP SDK Install :

In this example I Will Suppose your Source code will take in a Simple ‘facebook’ Directory in the root directory of your Website. First of All, make a blank in root Path ‘index.php’ file within your ‘facebook’ Directory. And then, We need to require the Facebook SDK for PHP.

Facebook approve We require the PHP SDK in your project using Download Composer, but We can also manually do so. In this example I will manually Put require the Facebook SDK, Therefor We First of All need to Simple All the Script Package download the Facebook SDK.

Also Read This 👉   Auto Post on Facebook page with php using Graph Api

Unzip the Facebook Package files and put the Simple Path the ‘src’ Directory in your ‘facebook’ Directory. Then include the Facebook SDK File in your Root index.php file Below Example:

//Include Facebook SDK Libs
define('FACEBOOK_SDK_V4_SRC_DIR', __DIR__.'/src/Facebook/');

//require autoload.php File

Step 3 : settings your Facebook App’s:

After that, We need to Setting your Facebook ‘App ID’ and Facebook ‘App secret’ keys into the source code below.step By step Get this code We can get your Facebook App’s ‘App ID’ and ‘App secret’ under the Main Home Facebook ‘dashboard’ tab Sections:

$fb = new Facebook\Facebook([
 'app_id' => 'YOUR_APP_ID',
 'app_secret' => 'YOUR_SECRET_KEY',
 'default_graph_version' => 'v2.2',

Step 4. Get Facebook Access Token for your Facebook App:

And then, if We want to Facebook Auto post Link and Data content to your Facebook Wall page like I needed to… We are gonna to need to get step By step a Facebook non-expiring Access Token for your Facebook page. And then Fisrt Of All the, Open Facebook Graph API Explorer and get Token. Here We Will Display an Simple Facebook ‘Application’ press button in the Facebook Developers Account’s top right cornrs as See below:

Automatically post to a Facebook page using the Facebook PHP API 3
Automatically post to a Facebook page using the Facebook PHP API 3

As We can Display, Just this is set to Facebook ‘Graph API Explorer’. Select your Facebook App instead. Now click the ‘get token’ button which We can also Display in the image above. Select First of all the ‘Get User Access Token’ As well as make simple sure the options select ‘publish_pages’ and ‘manage_pages’ granted permissions are ticked, then click the ‘Get Access Token’ button. Now click the ‘get token’ button again and select your Facebook page. We Just have your get Facebook Access Token which we need to Step By step convert into the Facebook non-expiring uniq Pass the Access Token. To do Therefor, pass param your Facebook App ID, Facebook App Secret Key as well as Facebook Access Token Put into the following Below URL:

//Get Access Token using this url

//pass param

After that All the copy Simple the token here provided.

Also Read This 👉   how to create dynamic calendar in html?

Step 5. post Content to a Facebook page Script:

after that, the source code that actually posts the content to the Facebook page. In Simple Script Intigrated PHP Code We wanted to Randomly loop using WordPress Images, posts, Content and post a link and Any More comment for any newly added the Simple posts onto my clients Facebook Wall page. Within my WordPress Randomly posts loop was the all important Source code below:

//Post All the Data property to Facebook
$linkData = [
 'link' => '',

try {
 $response = $fb->post('/me/feed', $linkData, $getTokenAccess);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
 echo 'Graph returned an error: '.$e->getMessage();
} catch(Facebook\Exceptions\FacebookSDKException $e) {
 echo 'Facebook SDK returned an error: '.$e->getMessage();
$graphNode = $response->getGraphNode();

There We go, if We now execute this file it will post your All the content to your Facebook wall page.

IMP Note: We Shall Display the post Link, Images appear on the Facebook Wall page, but no-one any else will as We have not set your Facebook Devloper web App Like as a ‘live’! Mode To do Therefor, Simple go back to your Facebook own Developers account and then select your devloper App. And next step to the Under the simple ‘Status & Review’select tab checked the checkbox at the top of the facebook page next to the text Like as a ‘Do We want to Create facebook app and all its live features here available to the all the data general public?’.

6. The automation on Facebook:

Last step all We needed was the simple Script Facebook automation. To simple this all We needed to do was set up a Your Webserver cron job that ran the Simple index.php file every any 5 hours or more amount of hours… as well as there was the Automatically post to a Facebook.

We hope you get an idea about Auto Post on Facebook with PHP script
We would like to have feedback on my Information blog .
Your valuable any feedback, Good question, Inspirational Quotes, or Motivational comments about this article are always welcome.
If you liked this post, Please don’t forget to share this as Well as Like FaceBook Page.

We hope This Post can help you…….Good Luck!.