facebook php sdk - 访问令牌为空

时间:2015-11-24 06:56:32

标签: php facebook facebook-php-sdk

我想询问Facebook时间轴和照片库,但访问令牌为空。

var authForms = document.getElementsByClassName('important');
function changeHash() {
    for(var i = 0; i < authForms.length; ++i) {
        var form = authForms[i];

        if (form.value === 'signup' && form.getAttribute('data-attr') === 'true') {
            location.hash = '#signup';
        } else {
            location.hash = '#login';
        }
    }
}
window.onload = changeHash;

回调php:

$this->FaceBookApp = new Facebook\Facebook(array(
        "app_id" => $this->appID,
        "app_secret" => $this->appSecret,
        "default_graph_version" => "v2.5"
));
$helper = $this->FaceBookApp->getRedirectLoginHelper();
$permissions = array('user_posts');
$loginUrl = $helper->getLoginUrl( _WEBPAGE .'/facebook-sdk/printAccessToken.php', $permissions);
echo "<script>window.top.location.href='".$loginUrl."'</script>";

当我尝试没有访问令牌时,

$helper = $this->FaceBookApp->getCanvasHelper();
try {
            $accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
            // When Graph returns an error
            echo 'Graph returned an error: ' . $e->getMessage();
            exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
            // When validation fails or other local issues
            echo 'Facebook SDK returned an error: ' . $e->getMessage();
            exit;
}
var_dump($accessToken);

是空数组。

请帮助我。

0 个答案:

没有答案