2012-07-08 60 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

我终于找到了答案。问题与代码无关。这是由于测试用户绕过了请求接受邀请的通知,而是直接输入了应用网址。

您必须删除测试用户并重新创建它。然后测试用户将收到一个新的通知,然后必须接受它。

相关问题