2014-09-06 89 views
2

我已經與laravel集成了hybridauth,並且能夠使用hybridauth通過twitter登錄到我的應用程序。當我第一次使用twitter登錄我的應用程序時,我已經授權我的應用程序。所以,通常在下次我不需要授權我的應用程序登錄因爲我已經接受授權的第一次。需要每次授權應用程序 - hybridauth laravel localhost

但它沒有發生。每當我嘗試登錄Twitter時,我的應用程序都迫使通過Twitter進行授權。

我想在本地主機上。我應該在活服務器上檢查它嗎?

我使用這個代碼,所有憑證都設置好的:

Route::get('social/{action?}', array("as" => "hybridauth", function($action = "") 
{ 
    // check URL segment 
    if ($action == "auth") { 
     // process authentication 
     try { 
      Hybrid_Endpoint::process(); 
     } 
     catch (Exception $e) { 
      // redirect back to http://URL/social/ 
      return Redirect::route('hybridauth'); 
     } 
     return; 
    } 
    try { 
     // create a HybridAuth object 
     $socialAuth = new Hybrid_Auth(app_path() . '/config/hybridauth.php'); 
     // authenticate with Google 
     $provider = $socialAuth->authenticate("Twitter"); 
     // fetch user profile 
     $userProfile = $provider->getUserProfile(); 
    } 
    catch(Exception $e) { 
     // exception codes can be found on HybBridAuth's web site 
     return $e->getMessage(); 
    } 
    // access user profile data 
    echo "Connected with: <b>{$provider->id}</b><br />"; 
    echo "As: <b>{$userProfile->displayName}</b><br />"; 
    echo "<pre>" . print_r($userProfile, true) . "</pre><br />"; 

    // logout 
    $provider->logout(); 
})); 

回答

1

我已經找到了解決辦法。它不是在代碼中解決某些問題。這是Twitter應用程序的設置。爲避免此類問題,您應該從應用設置的Permission部分中選擇Read and Write選項,而不是Read, Write and Access direct messages選項。

如果您選擇Read, Write and Access direct messages,那麼當您嘗試通過您的Twitter應用程序登錄您的應用程序時,twitter會始終提示您授權您的應用程序。請參閱下圖以獲取更多清晰的信息。

希望它能幫助你。謝謝 See the Image