问题
I am trying to create a Facebook application that uploads images to a page. I can manage to upload photos to the user's photo album but not to the page's.
Here's my code:
require_once('php-sdk/facebook.php');
$config = array(
'appId' => 'XXXXXXXX',
'secret' => 'YYYYYYYYYYYYYYYY',
'fileUpload' => true,
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
$photo = $_POST['image'];
$message = "Lorem ipsum";
echo $user_id;
if ($user_id) {
$ret_obj = $facebook->api('/XXXXXXXXXX/photos', 'POST', array(
'access_token' => $access_token,
'source' => '@' . $photo,
'message' => $message
)
);
} catch(FacebookApiException $e) {
$login_url = $facebook->getLoginUrl( array(
'scope' => 'user_photos,publish_stream,photo_upload'
));
echo 'Please <a href="' . $login_url . '">login.</a>';
print_r($e);
error_log($e->getType());
error_log($e->getMessage());
}
echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';
} else {
$login_url = $facebook->getLoginUrl( array( 'scope' =>user_photos,publish_stream,photo_upload,manage_pages' ) );
echo 'Please <a href="' . $login_url . '">login.</a>';
}
Any help would be much appreciated.
回答1:
When you do:
$facebook->api('/XXXXXXXXXX/photos', 'POST', array(
... is XXXXXXXXXX your appId or the albumId? You must do the call to your album ID.
Also make sure you are using the correct $access_token. To make sure look at:
https://graph.facebook.com/yourPageID?fields=access_token&access_token=YourPersonalAccessToken
where yourPersonalAccessToken is:
A Page admin
access_token
for this page; The current user must be an administrator of this page; only returned if specifically requested via thefields
URL parameter.
Your must grant to graph api manage_pages
permissions.
来源:https://stackoverflow.com/questions/11227369/facebook-php-sdk-app-to-upload-photo-to-page