2012-03-10 11 views
0

これは、許可のために私のコードです:のFacebookアプリのエラー

$permissions = $facebook->api("/me/permissions"); 
if(@array_key_exists('publish_stream', $permissions['data'][0])) { 
    // Permission is granted! 
    // Do the related task 
} else { 
    // We don't have the permission 
    // Alert the user or ask for the permission! 
echo '<script> 
window.location.replace("facebook.com/dialog/oauth?client_id=257378464344747&redirect_uri=https://www.facebook.com/pages/Test-Matyii/399406486739482?sk=app_257378464344747&scope=email,publish_stream"); 
</script>' ; 
} 

しかし、私はエラーがあります:あなたは正しく、例えば必ずセットアップPHP SDKにする必要があり

Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in /app/www/sdk/src/base_facebook.php on line 1106 
+0

を持つユーザのログインを持っている必要があります場合は、 '有効を指定する必要がありますあなたの '$ facebook-api'コールに' access_token'を書いてください – scibuff

+0

あなたの最初の行の前に来るコードを作成しますか? –

答えて

0

$facebook = new Facebook(array(
    'appId' => 'APP_ID', 
    'secret' => 'APP_SECRET', 
)); 

$user = $facebook->getUser(); 

if ($user) { 
    try { 
    $permissions = $facebook->api("/me/permissions");  
    // do something with the perms 
    } catch (FacebookApiException $e) { 
    error_log($e); 
    $user = null; 
    } 
} 

$ユーザは、ここに有効であるユーザーがログインしているとAPIへの呼び出しがnullの場合は動作するはずです、あなたはgetLoginUrl