2012-03-10 39 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>' ; 
} 

但我有錯誤:

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

您必須提供有效的' access_token'到你的'$ facebook-api'調用 – scibuff 2012-03-10 12:12:53

+0

Wheres第一行之前的代碼? – 2012-03-12 03:34:01

回答

0

你需要確保你安裝了PHP SDK正確例如

$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