2012-07-08 38 views
0

我遇到以下問題,這讓我發瘋。我使用Facebook PHP SDK(https://github.com/facebook/php-sdk/)發佈的示例代碼來識別用戶。對於我的大多數測試用戶來說,它工作正常,但對於某些用戶,實例創建不起作用。我試過用同一臺機器和不同的機器,它沒有改變任何東西。每個用戶在我的開發賬戶中都被正確設置爲測試用戶。Facebook應用程序實例創建不適用於每個用戶

可能是什麼原因? 非常感謝提前。

require '../lib/facebook.php'; 

    // Create our Application instance (replace this with your appId and secret). 
    $facebook = new Facebook(array(
     'appId' => 'XXXXXXXXXX', 
     'secret' => 'XXXXXXXXXXX', 
    )); 

    // Get User ID 
    $user = $facebook->getUser(); 

    if ($user) { 
     try { 
     // Proceed knowing you have a logged in user who's authenticated. 
     $user_profile = $facebook->api('/me'); 
     } catch (FacebookApiException $e) { 
     error_log($e); 
     $user = null; 
     } 
    } 

    // Login or logout url will be needed depending on current user state. 
    if ($user) { 
     $logoutUrl = $facebook->getLogoutUrl(); 
    } else { 
     $loginUrl = $facebook->getLoginUrl(array(
      'scope' => 'publish_stream, publish_actions', 
      'redirect_uri' => 'http://apps.facebook.com/xxxxx/' 
    )); 
    } 
    ?> 
    <!doctype html> 
    <html xmlns:fb="http://www.facebook.com/2008/fbml"> 
     <head> 
     <title>php-sdk</title> 
     </head> 
     <body> 
     <h1>php-sdk</h1> 

     <?php if ($user): ?> 
      <a href="<?php echo $logoutUrl; ?>">Logout</a> 
     <?php else: ?> 
      <div> 
      Login using OAuth 2.0 handled by the PHP SDK: 
      <a href="<?php echo $loginUrl; ?>" target="_top">Login with Facebook</a> 
      </div> 
     <?php endif ?> 

     <h3>PHP Session</h3> 
     <pre><?php print_r($_SESSION); ?></pre> 

     <?php if ($user): ?> 
      <h3>You</h3> 
      <img src="https://graph.facebook.com/<?php echo $user; ?>/picture"> 

      <h3>Your User Object (/me)</h3> 
      <pre><?php print_r($user_profile); ?></pre> 
     <?php else: ?> 
      <strong><em>You are not Connected.</em></strong> 
     <?php endif ?> 

     </body> 
    </html> 

回答

0

我終於找到了答案。問題與代碼無關。這是由於測試用戶繞過了請求接受邀請的通知,而是直接輸入了應用網址。

您必須刪除測試用戶並重新創建它。然後測試用戶將收到一個新的通知,然後必須接受它。

相關問題