2014-01-24 138 views
0

我已经注册了Facebook开发人员帐户的新应用程序。下面的教程,我有这样的代码:Facebook PHP SDK错误

<?php 
    // Remember to copy files from the SDK's src/ directory to a 
    // directory in your application on the server, such as php-sdk/ 
    require_once('facebook/facebook.php'); 

    $config = array(
    'appId' => 'xxxxxxxxxxxx', 
    'secret' => 'yyyyyyyyyyyyyy', 
    'allowSignedRequest' => false // optional but should be set to false for non-canvas apps 
); 

    $facebook = new Facebook($config); 
    $user_id = $facebook->getUser(); 
?> 
<html> 
    <head></head> 
    <body> 

    <?php 
    if($user_id) { 

     // We have a user ID, so probably a logged in user. 
     // If not, we'll get an exception, which we handle below. 
     try { 

     $user_profile = $facebook->api('/me','GET'); 
     echo "Name: " . $user_profile['name']; 

     } catch(FacebookApiException $e) { 
     // If the user is logged out, you can have a 
     // user ID even though the access token is invalid. 
     // In this case, we'll get an exception, so we'll 
     // just ask the user to login again here. 
     $login_url = $facebook->getLoginUrl(); 
     echo 'Please <a href="' . $login_url . '">login.</a>'; 
     error_log($e->getType()); 
     error_log($e->getMessage()); 
     } 
    } else { 

     // No user, print a link for the user to login 
     $login_url = $facebook->getLoginUrl(); 
     echo 'Please <a href="' . $login_url . '">login.</a>'; 

    } 

    ?> 

    </body> 
</html> 

我成立了应用信息中心: 应用程序域:buzzsu.com 网址:buzzsu.com

然后我www.buzzsu放在上面的代码。 COM。当我访问该页面时,它提供了我登录。当我点击登录,它给我以下错误:

Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains. 

我该如何解决它?

+0

在仪表板上,您添加了“buzzsu.com”或“www.buzzsu.com”吗?它很重要。 –

+0

好的!我编辑了www.buzzsu.com的应用程序设置。然后,在我尝试输入www.buzzsu.com并运行后,在firefox中我输入了buzzsu.com,但它不起作用。问题是什么? – torayeff

回答

1

我遇到同样的问题,我发现我的“redirect_uri”和“有效的OAuth重定向URI”存在不匹配。

在我的代码,我已经建立:

redirect_uri = "http://www.website.com/validate.php"; 

但在我的Facebook应用程序,我已经建立有效的OAuth重定向的URI:

http://website.com/validate.php 

我所缺失 “WWW”。所以我增加了一个有效的OAuth在我的Facebook应用重定向URI:

http://www.website.com/validate.php 




我的工作对我来说就像魔法。
希望它能帮助你。