2016-04-03 59 views
0

我正在嘗試使HybridAuth社交登錄(版本2.6.0)在這個簡單的PHP網站上工作。下載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

您需要添加一個檢查這樣的:

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

逸岸,當你說「我重定向與hauth_start/hauth_done頁面查詢字符串中的參數「,那麼您需要檢查是否存在該變量,如果找到,則調用process()靜態方法。

我從字面上發現了這個簡單的代碼行。 我從來沒有在文檔中找到或閱讀過文檔,但是如果您閱讀了關於Oauth2流程的內容,您將會明白,「流程的最後部分必須做些什麼」。

乾杯