本文介绍了Facebook PHP SDK应用程序,可将照片上传到页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个将图像上传到页面的Facebook应用程序.我可以将照片上传到用户的相册,但不能上传到页面的相册.
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.
这是我的代码:
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>';
}
任何帮助将不胜感激.
推荐答案
当您这样做:
$facebook->api('/XXXXXXXXXX/photos', 'POST', array(
... XXXXXXXXXX是您的appId还是albumId?您必须拨打您的相册ID .
... is XXXXXXXXXX your appId or the albumId? You must do the call to your album ID.
还要确保您使用的是正确的$ access_token.要确保查看:
Also make sure you are using the correct $access_token. To make sure look at:
其中yourPersonalAccessToken为:
where yourPersonalAccessToken is:
您必须授予对图api manage_pages
的权限.
Your must grant to graph api manage_pages
permissions.
这篇关于Facebook PHP SDK应用程序,可将照片上传到页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!