Few days ago I have started working on status publishing on Facebook using PHP and faced few problems to do that so, today I have decided to write an article on it how to publish status on Facebook using graph API with source code download and a demo so you never face any issue next time to make something like that.
To create facebook application follow instruction on my previous post How to Login with Facebook Graph API in PHP
Script contains two folders called oAuth and images with PHP files.
– base_facebook.php // Class Get user Information
– facebook.php // Class Get user Information
– config.php // Configuration file
html.inc // html design view
index.php // Main index file
<?php $config['callback_url'] = 'CALL BACK URL/?fbTrue=true'; // /?fbTrue=true allow you to code process section. //Facebook configuration $config['App_ID'] = 'Your App ID'; $config['App_Secret'] = 'Your App Secret'; ?>
Shows you 2 buttons ask for permission and show text box to add status to publish 2nd button publish status right after permission allowed.
<?php require 'src/config.php'; require 'src/facebook.php'; // Create our Application instance (replace this with your appId and secret). $facebook = new Facebook(array( 'appId' => $config['App_ID'], 'secret' => $config['App_Secret'], 'cookie' => true )); $publish = $facebook->api('/me/feed', 'post', array('access_token' => $params['access_token'], 'message'=>'This Messsage published by PHPGang.com Demo.', 'from' => $config['App_ID'] )); $message = 'Default status updated.<br>'; ?>
In this file me show you instead me you can also write your id you also can change this me to any your friend id to post feed on any of your friends wall if he opens to do that you have to get its permission
Note: Publish status on your wall needs publish_stream permission