0

I am trying to make this script from almost 4-6 hrs, but no luck. I have a facebook page, facebook app and facebook account. I want to code in a way that it should be able to post on my facebook page without any human interaction. I am using below code

    require_once("application/libraries/facebook-php-sdk-master/src/facebook.php");

    // initialize Facebook class using your own Facebook App credentials
    // see: https://developers.facebook.com/docs/php/gettingstarted/#install
    $config = array();
    $config['appId'] = '{appid}';
    $config['secret'] = '{appsecret}';
    $config['fileUpload'] = false; // optional

    $fb = new Facebook($config);
    // define your POST parameters (replace with your own values)
    $params = array(
      "access_token" => "{token}", 
      "message" => "Here is a blog post about auto posting on Facebook using PHP #php #facebook"
    );

    try {
      $ret = $fb->api('/mypagename/feed', 'POST', $params);
      echo 'Successfully posted to Facebook';
    } catch(Exception $e) {
      echo $e->getMessage();
    }

Using "User Access token" in API explorer i am able to post to fb page but as a "Visitor" not as admin, and if i use "App token" i get error message

{
  "error": {
    "message": "(#200) The user hasn't authorized the application to perform this action",
    "type": "OAuthException",
    "code": 200,
    "fbtrace_id": "Bk30JLt+skw"
  }
} 

How do i add permission to post to my own facebook wall, is it even possible ?

www.amitpatil.me
  • 3,001
  • 5
  • 43
  • 61
  • i haven't used the php sdk yet but the general process is to hit the /pages graph endpoint to get the page ids of the pages you manage, then get an access token for that page, THEN post to the page.. you need manage_pages permission – Robert Parham Sep 27 '16 at 20:45
  • also i'm pretty sure this has been answered before.. try googling.. – Robert Parham Sep 27 '16 at 20:45
  • this has been answered a hundred times already, yes. – andyrandy Sep 27 '16 at 20:47
  • well, that duplicate question does not have a good answer, but there are hundreds of other threads about it and it is very clear in the api reference of facebook too. you need a page token, that is all. – andyrandy Sep 27 '16 at 20:49
  • I googles a lot, found few stackoverflow question exactly similar, but none of them are marked as answered, i even tried answers upvoted by users. but that doesnt even worked. Atleast i got a clue here, i need a "page token", is it different from "User Access token" and "App token" ? – www.amitpatil.me Sep 27 '16 at 21:06

0 Answers0