我期待使用 php 和 facebook sdk 开发一个应用程序,以便我可以更改粉丝页面的封面图像。
我是我创建的应用程序的管理员,并使用相同的 appId 和 appSecret。
在这里我发布我的源代码,任何帮助将不胜感激。
它抛出异常“未捕获的 OAuthException:(#10)应用程序没有此操作的权限”
require 'php-sdk/facebook.php';
$app_id = "My App ID";
$app_secret = "My App Secret";
$post_login_url = "URL";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$user_fb = $facebook->getUser();
if($user_fb == 0)
{
$user_fb = $facebook->getUser();
}
if ($user_fb)
{
$user_profile = $facebook->api('/me');
$user_friends = $facebook->api('/me/friends');
$logoutUrl = $facebook->getLogoutUrl();
}
else
{
$perms = array('scope' => 'user_photos,photo_upload,manage_pages,publish_stream', 'redirect_uri' => '');
$loginUrl = $facebook->getLoginUrl($perms);
echo "<script>top.location.href='" . $loginUrl . "'</script>";
}
$pageIds=$facebook->api('/me/accounts');
$pageAccessToken=$pageIds["data"][1]["access_token"];
$facebook->setAccessToken($pageAccessToken);
$facebook->setFileUploadSupport(true);
//Create an album
$album_details = array(
'message'=> 'My New Album',
'name'=> 'My New Album'
);
$create_album = $facebook->api('/me/albums', 'post', $album_details);
$album_uid = $create_album['id'];
$photo_details = array(
'message'=> 'Testing facebook API'
);
$file='images/Tanveer1.png';
$photo_details['image'] = '@' . realpath($file);
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
$make_cover_image = array(
'cover'=> $upload_photo['id'],
'offset_y'=> '60',
);
$json_object = $facebook->api("/Fan_Page_ID/?access_token=".$pageAccessToken,'post',$make_cover_image);
print_r($json_object);