Wednesday, 21 August 2013

facebook php sdk - Error #200 when trying to use setExtendedAccessToken

facebook php sdk - Error #200 when trying to use setExtendedAccessToken

I have been trying for several days now to successfully post to a client's
Facebook Page wall from their website. I need to be able to do this
without having a user logged in, which I was able to achieve with an
extended access token generated by going to the URL provided in the docs.
What I am trying to do is to fetch an extended token using the PHP SDK as
in this question - Facebook PHP SDK: getting "long-lived" access token now
that "offline_access" is depricated, however I receive the following
error: (#200) The user hasn't authorized the application to perform this
action
The debug of the auth token generated by the Graph API Explorer shows
myself as the User and includes the needed manage_pages and status_update
scopes. However, if I run me/accounts, the perms array does not list these
under the data for the page in question - not sure if this is relevant.
Here is the code that I have attempted to use:
$facebook = new Facebook(array('appId' => 'xxxxxxx', 'secret' => 'xxxxxx'));
$pageID = 'xxxxxxxx';
$facebook->setExtendedAccessToken();
$accessToken = $facebook->getAccessToken();
try {
$page_info = $facebook->api("/$pageID?fields=access_token");
print_r ($page_info);
} catch (FacebookApiException $e) {
echo $e->getMessage();
}
if( !empty($accessToken) ) {
$args = array(
'access_token' => $accessToken,
'message' => "Catch phrase!"
);
$facebook->api("/$pageID/feed","post",$args);
} else {
// Handle error
}

No comments:

Post a Comment