2016-09-21 37 views
2

我想測試我的web應用程序在本地主機上有Facebook登錄設施。 但我收到以下錯誤URL被阻止:Facebook登錄使用php sdk

URL阻止:此重定向失敗,因爲重定向URI沒有在應用程序的客戶端的OAuth設置白名單。確保客戶端和Web OAuth登錄已打開,並將所有應用程序域添加爲有效的OAuth重定向URI。

我已經在FB應用程序的設置中將應用程序域作爲localhost和站點url作爲http://localhost

我的代碼

if (isset($_GET['code'])) { 


     header('Location: http://localhost'); 
    } 

    // getting basic info about user 
    try { 
     $profile_request = $fb->get('/me?fields=name,first_name,last_name'); 
     $profile = $profile_request->getGraphNode()->asArray(); 
    } catch(Facebook\Exceptions\FacebookResponseException $e) { 
     // When Graph returns an error 
     echo 'Graph returned an error: ' . $e->getMessage(); 
     session_destroy(); 
     // redirecting user back to app login page 

     header('Location: http://localhost'); 

     exit; 
    } 
       : 
       : 
       : 
{ 
    // if not logged in display 

    $loginUrl = $helper->getLoginUrl('http://localhost/index.php'); 
    echo "<div style=\"padding-top:5%;\"><h1>why so serious?</h1> 
        <span><a href=\"".$loginUrl ."\" class=\"email\">LOGIN WITH FACEBOOK</a></span></div> 

        "; 

} 
+1

[這個問題](http://stackoverflow.com/questions/34169276/javascript -parse-facebook-login-issue)和[它是重複的](http://stackoverflow.com/questions/34477847/facebook-login-with-javascript-sdk-error-redirect-uri-not-whitelisted)可能是相關的。第二個問題有幾個有用的鏈接。 – Terminus

+0

@Terminus它並沒有解決問題。但有幫助+1 – jophab

+0

產品 - > Facebook登錄。如果那還沒有,你需要先添加它。 – CBroe

回答

3

這裏是解決方案。由於@CBroe

PRODUCTS標題,選擇Facebook Login 現在給http://localhostValid OAuth redirect URI 下,然後保存更改

image