简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM