我已将hybridauth与laravel集成,并且能够使用hybridauth通过twitter登录我的应用程序。当我第一次使用Twitter登录我的应用程序时,我已经授权我的应用程序。所以,通常在下次我不需要授权我的应用程序登录,因为我已经第一次接受授权。
但它没有发生。每当我尝试登录twitter时,我的应用程序都会强制通过Twitter进行授权。
我在localhost上尝试这个。我应该在实时服务器上查看吗?
我正在使用此代码,所有凭据都已设置:
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();
}));
答案 0 :(得分:1)
我找到了解决方案。它不是在代码中修复的东西。这是twitter应用程序的设置。要避免此类问题,您应该从应用设置的Read and Write
部分选择Read, Write and Access direct messages
选项,而不是Permission
选项。
如果您选择Read, Write and Access direct messages
,那么每当您尝试通过Twitter应用登录应用时,Twitter都会提示您授权您的应用。有关更多信息,请参见下图:
希望它会对你有所帮助。谢谢