2011-07-21 14 views
5

自分のサイトのFacebookログインのリダイレクトURLを変更しようとしています。これは、すでに存在していない場合はデータベースに新しいユーザーを作成し、メインページにリダイレクトするページに移動できるようにするためです。 An error occurred with PHP SDK Unit Tests. Please try again later.ログイン時にFacebookのリダイレクトURLを変更します

私のコード(私はmysite.com/createfbuser.phpするためにそれらをリダイレクトする)::

public function getLoginUrl($params=array()) { 
    $this->establishCSRFTokenState(); 
    $currentUrl = $_SERVER['SERVER_NAME'] . '/createfbuser.php'; 
    return $this->getUrl(
     'www', 
     'dialog/oauth', 
     array_merge(array(
       'client_id' => $this->getAppId(), 
       'redirect_uri' => $currentUrl, // possibly overwritten 
       'state' => $this->state, 
       'scope' => 'email'), 
     $params)); 
} 

EDITのIがログインしようとすると、しかし、私は、Facebook上で次のエラーを取得します元のコードは参照用に$currentUrl = $this->getCurrentUrl();と表示されます

答えて

5

リダイレクト先のURLは、アプリの設定でアプリに設定したのと同じドメインにする必要があります。それ以上の制限はありません。本当にredirect_urlをanyドメインのURL。

あなたが管理者としてアプリをのauthしようとすると目に見える具体的なエラーメッセージがあるはず - それは非常に可能性の高いエラー191です(別の考えられる原因と解決策のためのFacebook API error 191を参照)、すべての

+0

を参照してください、豚。そうするだろう。 – tnw

7

まず、あなたは「ドントン以下、PHP SDKを編集しているのは

はあなたが交換することを確認し、ユーザを認証してからランディングページにリダイレクトするためのサンプルです:

YOUR-APP-ID-HERE自分のFacebookのアプリケーションIDと、

YOUR-APP-API-SECRET-HERE自分のFacebookのアプリケーション秘密鍵

YOUR-REDIRECT-URL-HEREとリンク先ページのURLと

<?php 

    // Requires Facebook PHP SDK 3.0.1: https://github.com/facebook/php-sdk/ 
    require ('facebook.php'); 

    define('FACEBOOK_APP_ID',"YOUR-APP-ID-HERE"); 
    define('FACEBOOK_SECRET',"YOUR-APP-API-SECRET-HERE"); 
    define('REDIRECT_URI',"YOUR-REDIRECT-URL-HERE"); 
    $user = null; 

    $facebook = new Facebook(array(
     'appId' => FACEBOOK_APP_ID, 
     'secret' => FACEBOOK_SECRET, 
     'cookie' => true 
    )); 

    $user = $facebook->getUser(); // Get the UID of the connected user, or 0 if the Facebook user is not connected. 

    if($user == 0) { 
     // If the user is not connected to your application, redirect the user to authentication page 
     /** 
     * Get a Login URL for use with redirects. By default, full page redirect is 
     * assumed. If you are using the generated URL with a window.open() call in 
     * JavaScript, you can pass in display=popup as part of the $params. 
     * 
     * The parameters: 
     * - redirect_uri: the url to go to after a successful login 
     * - scope: comma separated list of requested extended perms 
     */ 

     $login_url = $facebook->getLoginUrl($params = array('redirect_uri' => REDIRECT_URI)); 

     echo ("<script> top.location.href='".$login_url."'</script>"); 

    } else { 
     // if the user is already connected, then redirect them to landing page or show some content 
     echo ("<script> window.location.href='".REDIRECT_URI."'</script>"); 
    } 

?> 

あなたは、拡張アクセス権を取得したい場合は、単に追加別のログインURL、元の「スコープ」パラメータ:権限の詳細については

$login_url = $facebook->getLoginUrl($params = array('redirect_uri' => REDIRECT_URI,'scope' => 'comma-separated-list-of-requested-extended-perms')); 

、やるfacebook permissions docs

+0

私はあなたが入った詳細を感謝し、upvoted。しかし、私は元のコードを手に入れることができましたが、それは私のためには簡単ですが、ありがとうございました。 – tnw

+0

@Tory Waterman:ありがとう、それは問題ありません。 –

関連する問題