November 18, 2013 9:18 am

How to publish status on Facebook with Graph API

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.

How to publish status on Facebook with 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 oAuth and images with PHP files.

src

– base_facebook.php // Class Get user Information

– facebook.php // Class Get user Information

– config.php // Configuration file

images

html.inc // html design view

index.php // Main index file

PHP Code

Edit config.php

Shows you 2 buttons ask for permission and show text box to add status to publish 2nd button publish status right after permission allowed.

index.php

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

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:
  • Avais Khatri

    I am not able to publish a status on facebook. Although i have added app_id and app_secret _ config,ph

    • huzoorbux

      What error you are getting on posting.

      • Avais Khatri

        when someone click the login button the app ask for permsions than its redirect to call back function and no error occurs

  • test

    Great tut ! post status with image is possible ?

  • Val

    It is possible to provide a link preview ?

  • ashulbha12

    can u please tell me concept of me in ‘$publish = $facebook->api(‘/me/feed’, ‘post’,’.

    because i m getting Uncaught OAuthException error

    • huzoorbux

      This line is api call to post your status. post your error here so i can help you more.

      • ashulbha12

        Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in /home/yogendra/public_html/facebook/src/base_facebook.php on line 1243

    • ashulbha12

      Uncaught OAuthException: (#200) The user hasn’t authorized the application. and i have changed i have change the secret id and app id in config.php .

      Should i replace ‘me’ to any ID?

    • huzoorbux

      If your app asks for more than than public_profile, email and user_friends it will require review by Facebook before your app can be used by people other than the app’s developers.

      The time to review your app is usually about 7 business days. Some extra-sensitive permissions, as noted below, can take up to 14 business days.

      Learn more about our review process https://developers.facebook.com/docs/apps/review

  • ankit

    i have change the secret id and app id in config . and when i update the post it show me error “Uncaught OAuthException: (#200) The user hasn’t authorized the application to perform this action thrown in /facebook/src/base_facebook.php on line 1243”.
    what should i do for this?

    • huzoorbux

      If your app asks for more than than public_profile, email and user_friends it will require review by Facebook before your app can be used by people other than the app’s developers.

      The time to review your app is usually about 7 business days. Some extra-sensitive permissions, as noted below, can take up to 14 business days.

      Learn more about our review process https://developers.facebook.com/docs/apps/review.

  • Max John

    I tested the demo online and i get this error

    Fatal error: Uncaught FacebookApiException: Duplicate status message
    thrown in
    /hermes/waloraweb002/b2497/pow.huzoorbuxcom/htdocs/phpgang/demo/post-status-facebook/src/base_facebook.php
    on line 1243

    • huzoorbux

      Just checked its working fine please test it again

      • Max John

        Thanks now it is working. Should i re-download the file or the one i have downloaded is already corrected ?

        • huzoorbux

          No need to re-download it.

  • Stefanie Beutlich

    Is it possible to get any answer from facebook after posting a status message? Like the ID of the post or anything?

    • huzoorbux

      Yes its possible use var_dump($publish); after publish and get result returned by facebook.

      $publish = $facebook->api('/me/feed', 'post',

      array('access_token' => $params['access_token'],

      'message'=>'This Messsage published by PHPGang.com Demo.',

      'from' => $config['App_ID']

      ));

      var_dump($publish);

  • Sam Bot

    help me plz error :
    Fatal error: Uncaught CurlException: 7: couldn’t connect to host thrown in /home/xxxxxxxxx/facebook_sdk/scr/base_facebook.php on line 1012

  • harpreet

    your code for post on page was successful but how can i post on facebook’wall??