Facebook SDK post photo likes
I try to post a photo like on behalf of the current user. But i get #200 Permission Error. What i am doing wrong? Need i other permissions? I tried also with all permissions, still no luck.
require_once 'facebook-php-sdk/src/facebook.php';
class photo_liker {
function __construct()
{
$this->facebook = new Facebook( array('appId' => fb_appID, 'secret' => fb_secret, 'fileUpload' => true, 'cookie' => true));
}
function postPhotoLike($photoid)
{
try {
$args = array('access_token' => $this->facebook->getAccessToken());
$upload_photo = $this->facebook->api('/' . $photoid . '/likes', 'post', $args);
} catch (FacebookApiException $e) {
var_dump($e);
}
}
function login()
{
try {
$uid = $this->facebook->getUser();
} catch (Exception $e) {
var_dump($e);
}
if($uid) {
try {
$user = $this->facebook->api('/me');
} catch (Exception $e) {
var_dump($e);
}
return true;
开发者_高级运维} else {
$login_url = $this->facebook->getLoginUrl(array('scope' => 'email,publish_stream'));
ob_clean();
echo("<script>top.location.href='" . $login_url . "'</script>");
exit ;
}
return false;
}
}
$test = new photo_liker();
$test->login();
$test->postPhotoLike('10150758570710223');
Ok it was because the test users from Facebook dev had not liked the page on with the photo was posted. If they like the page all goes right.
精彩评论