简体   繁体   中英

PHP Facebook API Post on page's wall

I know, this question was asked hundred times, but none of the given solutions works for me. I'm trying to post on the wall of every page the current user owns. So, I first get the permissions to publish_actions, read_stream, manage_pages and offline_access. Then I check via /me/permissions, that the user really granted those permissions.

Then, I try to get all pages of the user and post on the wall of the page, if the user is the admin:

$accounts = $facebook->api("/me/accounts", "GET", array("access_token"=>$facebook->getAccessToken()));

$data = $accounts["data"];

foreach ($data as $page)
{
    if (isset($page["perms"]) && in_array("CREATE_CONTENT", $page["perms"])))
    {
        $facebook->api("/".$page["id"]."/feed", "POST", array("link"=>$link, "access_token"=>$page["access_token"]));
    }
}

But, posting on the wall of the page fails, with the well known error message

Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action

Any ideas? Where's my fault?

If you can make the same call via the Graph API Explorer or cURL for one of the pages then your logic is right. So I would place a try/catch on the page/id call to see if a specific page is messing up the loop.

try {
    $facebook->api("/".$page["id"]."/feed", "POST", array("link"=>$link, "access_token"=>$page["access_token"]));
  } catch (FacebookApiException $e) {
    error_log($e . " for: " .$page["id"] );
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM