2011-08-28 39 views
0

我的Facebook應用程序最初是要求用戶的基本許可,現在我添加了一些功能,需要擴展認證,除了將代碼更改爲如下所示,添加應用程序,我需要改變應用程序的其他任何東西。Facebook應用程序現在要求擴展許可,而不是基本的,

因爲當我從我的個人資料中刪除應用程序,然後試圖重新添加它,它只要求基本信息,我該如何告訴Facebook現在應用程序需要擴展權限,因爲它給我這個警告:OAuthException: (#200)用戶尚未授權應用程序執行此操作。

我需要重置更改某些設置的應用程序祕密嗎?

> $facebook = new Facebook(array( 'appId' => 'xxxxxxxxxxxx', 
> 'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',)); 
> 
> // Get User ID 
> 
> 
> $user = $facebook->getUser(); if ($user) { try { 
>  // Get the user profile data you have permission to view 
>  $user_profile = $facebook->api('/me'); 
>  $uid = $facebook->getUser(); 
>  
>  
>  $url = $facebook->getLoginUrl(array(
>  'canvas' => 1, 
>  'fbconnect' => 0, 
>  'scope' =>'publish_stream')); 
>  
>  
>  $attachment = array ( 
> 'access_token'=>$facebook->getAccessToken(), 'message' => 'I had a 
> question: should I write a PHP facebook app that actually worked?', 
> 'name' => 'I Asked Bert', 'caption' => 'Bert replied:', 'link' => 
> 'http://apps.facebook.com/askbert/', 'description' => 'NO', 
> 'picture' => 'http://www.facebookanswers.co.uk/img/misc/question.jpg' 
>); echo "Test 1"; 
> 
> $result = $facebook->api('/me/feed/','post',$attachment); 
> 
>  echo "Test 2"; 
>  $_SESSION['userID'] = $uid; 
> 
> 
> } catch (FacebookApiException $e) { 
>  $user = null; } } else { die('Somethign Strange just happened 
> <script>top.location.href="'.$facebook->getLoginUrl().'";</script>'); 
> } 

回答

1

下面的代碼正在工作,事情是先檢查權限,然後發佈流,如果沒有發現權限,然後詢問用戶的權限。

$facebook = new Facebook(array(
    'appId' => 'xxxxxxxxxxxxxxxxxx', 
    'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 
)); 
$user = $facebook->getUser(); 
$user_profile = $facebook->api('/me'); 


if(array_key_exists('publish_stream', $permissions['data'][0])) { 
       // Permission is granted! 
       // Do the related task 
       //$post_id = $facebook->api('/me/feed', 'post', array('message'=>'Hello World!')); 
        $post_id = $facebook->api('/me/feed', 'post', $attachment); 

      } else { 
       // We don't have the permission 
       // Alert the user or ask for the permission! 
       echo "Click Below to Enter!"; 
       header("Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream"))); 
      } 
1

如果您使用的是較新的3.0 PHP SDK,那麼在調用getLoginUrl時將req_perms更改爲範圍。這在更新的PHP SDK版本中發生了變化。

此外,您需要驗證用戶是否仍然授予您的應用程序所需的擴展權限,如果他們沒有,請重新提示他們以獲取權限。例如,您捕獲一個FacebookApiException,然後將它們重定向到getLoginUrl(),但該登錄名還應指定您需要的範圍,就像您在代碼中所做的那樣。

+0

感謝您的建議,但例外的是仍然存在 – PUG

+0

做出 – PUG

+2

作出了更新的變化。最後如果有api異常(又稱沒有權限),你有第二個getLoginUrl。添加該調用所需的範圍。 – bkaid

相關問題