2014-01-24 163 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 




我的工作對我來說就像魔法。
希望它能幫助你。