问题
I'm trying to add a feature to my app that will post a status to a admin user's page timeline with the same detail as if they posted on Facebook.com. The main feature I am focusing on is the link sharing and thumbnail images, like when you paste a link into your status and it auto-detects a thumbnail image, gives you a nice link, description, etc. I have tireless read through other forums and the Graph API documents, and I keep running into problems with the post showing as the admin user, rather than the page. Here is my code:
$facebook = new Facebook(array(
'appId' => $appID,
'secret' => $appSecret,
));
$loginUrl = $facebook->getLoginUrl(array(
"scope" => 'publish_stream, read_insights, manage_pages, photo_upload, video_upload, create_note, manage_notifications'
));
$access_token = $facebook->getAccessToken();
$fbpost = array();
$fbpost['access_token'] = $access_token;
$fbpost['message'] = $message;
$fbpost['link'] = $link;
$fbpost['description'] = $description;
$fbpost['caption'] = $caption;
$fbpost['picture'] = $fbimg;
$status = $facebook->api('/'.$pageID.'/feed', 'POST', $fbpost);
var_dump($status);
When I only post the $fbpost['message'] it correctly posts the status as the page, but when I add ANYTHING else it shows the post as the authenticated admin user instead of the page. Very frustrating. Any ideas?
回答1:
I keep running into problems with the post showing as the admin user, rather than the page.
Then get a page access token, not a user access token for the admin user …
回答2:
Thanks to CBroe for providing a link to the Facebook docs on the page/app access token. After checking that out, I came up with this PHP (since there is no good documentation in the PHP SDK for getting a page access token):
$user_token = $facebook->getAccessToken();
$accounts = $facebook->api('/me/accounts?access_token='.$user_token);
$account_token = 0;
foreach ($accounts['data'] as $account) {
if ($account['id'] == $_SESSION['facebook']) {
$account_token = $account['access_token'];
}
}
if ($account_token) {
/// your page token code
} else {
echo 'You must be an admin on this page!';
}
来源:https://stackoverflow.com/questions/11054915/facebook-php-sdk-graph-api-post-to-page-not-functioning-properly