Question

I'm creating a CMS for a website, and want to add functionality to post something (for example: news) to that website's FB Page [not to a user profile].

I've read FB's documentation, and could find out that I need to have a FB application, which must have access to that Page. Then I'll be able to authenticate from my website as Application and post the link on the Page.

I've created sample Page, and an empty Application (no working code). Then I've added it to the Page [on App Profile Page there is a button "Add to my page"]. The Application never requested any permissions, and, in fact, I don't know how can I "force" my App to request permissions from Page...

Now, from my server I'm authenticating as Application:

$postArr = Array(
            'grant_type'=>'client_credentials',
            'scope'=>'publish_stream',
            'client_id'=>$appId,
            'client_secret'=>$appSecret
            );
$access_token = CURL_post('https://graph.facebook.com/oauth/access_token',$postArr,true);

I get an Access Token, and try to post to the Page's wall:

$postArr = Array(
            'access_token'=>$access,
            'message'=>"Message!",
            'link'=>'http://egern.net/',
            'name'=>"TITLE",
            'caption'=>"TITLE2!");
$r = CURL_post("https://graph.facebook.com/MYPAGEID/feed",$postArr,true);

I get following error: (#200) The user hasn't authorized the application to perform this action

Now I can't understand: how should the Page authorize the Application?

Thanks.

Was it helpful?

Solution

To be able to post to your page using the graph api there's a couple of steps to do this:

  1. The admin of the page needs to install your application with permission manage_pages, reference. And publish_stream for step 3
  2. Now querying the accounts method ->api('/me/accounts?access_token=XXX') with the access_token you just obtained will retrieve all your pages (accounts) with their corresponding access_token
  3. use the page access_token to post your "news" to your page ->api('/page_id/feed', 'post', $postArr)

Almost same instructions are available here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top