January 27, 2014 3:13 pm

How to post into a Facebook Page with PHP using Graph API

We have published one article on How to publish status on Facebook with Graph API which post status on user’s wall when user write , now I am going to show how to post status on pages to post status on Facebook page we use Facebook Graph API in PHP to perform this task.

How to post into a Facebook Page with PHP using Graph API

To create Facebook application follow instruction on my previous post How to Login with Facebook Graph API in PHP

Script contains two folders called src and images with PHP files.


– base_facebook.php // Class Get user Information.

– facebook.php // Class Get user Information.

– config.php // Configuration file.


index.php // Main index file.

PHP Code

Edit config.php

On the main page show you one button for connect with PHP on redirect to Facebook it will ask you for permission here we add one more permission which is manage_pages with this permission you will allow that application to manage your pages.


Explanation of above code:

We will call this URL to get Facebook profile token.

On callback page it will give you a code parameter using that code you will call this URL in backhand and get access token.

After that we got the access token of that user with manage pages permission in $response variable.

Now use that token and get all pages under that user account and their access tocke.


This page show you all pages token and page name and id’s in demo we show dropdown of pages you can select any page and add status in text box and publish it will publish it on your page.

Create a drop down from above json code is very simple and easy here is the snippet for that.

Status Publish Code

There is 2 code snippet one can share link on page with custom image and description like blow:

The above code can share a link like this screenshot:


2nd snippet of sharing which only share your text on the page and if you include any link it will extract that link itself and show title image and description.

Screenshot of status posted by above snippet:


 This is the simple scenario of posting on Facebook pages I hope you like this tutorial so please give your feedback in comments.

Author Huzoor Bux

I am Huzoor Bux from Karachi (Pakistan). I have been working as a PHP Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically I am a PHP developer but now days exploring more in HTML5, CSS and jQuery libraries.

Tutorial Categories: