2014-09-06 30 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

相关问题