2016-04-03 25 views
0

この単純なPHPサイトでHybridAuthソーシャルログイン(バージョン2.6.0)を動作させようとしていました。 HybridAuthをダウンロードしてインストールしました。 リンクをクリックしてソーシャルネットワーク(Facebook)にログインするたびに、(MY_BASE_URL/index.php?hauth.start = Facebook & hauth.time)にログインウィンドウやエラーメッセージが表示されずにリダイレクトされます。ここでHybridAuth:リダイレクト後にユーザー情報を取得する方法

はかかわりのためのファイルです。ここで

$config ="../hybridauth/config.php"; 
require_once("../hybridauth/Hybrid/Auth.php"); 


try{$hybridauth = new Hybrid_Auth($config); 
    $provider = @ trim(strip_tags($_GET["provider"])); 
    $adapter = $hybridauth->authenticate($provider); 
    $adapter = $hybridauth->getAdapter($provider); 
    $user_data = $adapter->getUserProfile(); 
    if($user_data) 
    { 
    print_r($user_data); 
    } 
    else 
    {    
    echo '******* CRASH *******';   
    exit; 
    } 
} 
catch(Exception $e){  

    switch($e->getCode()){ 
    case 0 : echo "Unspecified error."; break; 
    case 1 : echo "Hybriauth configuration error."; break; 
    case 2 : echo "Provider not properly configured."; break; 
    case 3 : echo "Unknown or disabled provider."; break; 
    case 4 : echo "Missing provider application credentials."; break; 
    case 5 : echo "Authentication failed. " 
       . "The user has canceled the authentication or the provider refused the connection."; 
    case 6 : echo "User profile request failed. Most likely the user is not connected " 
       . "to the provider and he should to authenticate again."; 
      $adapter->logout(); 
      break; 
    case 7 : echo "User not connected to the provider."; 
      $adapter->logout(); 
      break; 
} 
echo "<b>Original error message:</b> " . $e->getMessage(); 
    echo "<hr /><h3>Trace</h3> <pre>" . $e->getTraceAsString() . "</pre>";  
} 

は、設定ファイルである:

return 
    array(
     "base_url" => "http://woonmako.com/hybridauth/index.php", 
     "providers" => array(

      "Google" => array(
       "enabled" => true, 
       "keys" => array("id" => "", "secret" => ""), 
      ), 
      "Facebook" => array(
       "enabled" => true, 
       "keys" => array("id" => "*********", "secret" => "***********"), 
       "trustForwarded" => false 
      ), 
      "Twitter" => array(
       "enabled" => true, 
       "keys" => array("key" => "", "secret" => ""), 
       "includeEmail" => false 
      ), 
     ), 

     "debug_mode" => false, 
     "debug_file" => "", 

)。

私はそれがどのように仕事で、どのファイルでユーザーの情報を入手しなければならないか知りたいと思います。

答えて

0

Hybrid_User_Profileハイブリッド/ユーザー/ Profile.php Hybrid_User_Profileは

1.objectは、ユーザプロファイルに記録電流を表します。 HybridAuthで使用される正規化されたユーザープロファイル構造で使用可能なフィールドのリスト。 The

2.オブジェクトには、HybridAuthが指定されたAPIまたは認証プロバイダからプルできるように、ユーザーに関する情報が設定されています。

// try to authenticate the user with Twitter 
$twitter_adapter = $hybridauth->authenticate("Twitter"); 

// get the user profile 
$twitter_user_profile = $twitter_adapter->getUserProfile(); 

// debug the received user profile 
print_r($twitter_user_profile); 

// echo the user profile page on twitter >> http://twitter.com/<username> 
echo $twitter_user_profile->profileURL; 

Properties of Hybrid_User_Profile Class

と詳細あなたがhere

0

を得ることができます私はちょうど今、同じ問題を抱えていたし、検索やテストの多くの後に解決しました。 最後に、レスポンスの「処理」の最後の部分だけが失われます。

このスレッドを見てみましょう: https://stackoverflow.com/a/31795036/6018431

あなたはこのようなチェックを追加する必要があります:あなたは「私はhauth_start/hauth_doneのページにリダイレクトさだと言う

if (isset($_REQUEST['hauth_start']) || isset($_REQUEST['hauth_done'])) { 
    Hybrid_Endpoint::process(); 
} 

Infactは、その時点であなたはそのvarsの存在をチェックする必要があり、見つかった場合はprocess()静的メソッドを呼び出します。

この単純なコード行を見つけるために、私は文字通り驚いた。 ドキュメントを見つけたり読んだりしたことはありませんでしたが、Oauth2のフローについて読んだら、「フローの最後の部分に何かを作らなければならない」ということを理解するでしょう。

乾杯

関連する問題