为了增加网站的社交登录功能,我正在使用杂交 php库开源社交标志。
但是,当我想通过twitter帐户登录到网站时,上面提到的错误信息是显示的,没有任何细节。
“身份验证失败!Twitter返回了一个错误”
我认为所有的脚本和选项都是正确的,但是仍然显示错误。
这是一段config.php文件:
return
array(
"base_url" => "http://emrc-tgf.org/vendor/hybridauth/hybridauth/hybridauth/",
"providers" => array(
"Google" => array (
"enabled" => true,
"keys" => array ( "id" => "82763127799-sfdsoe990b9ugu0g7l0mlll0u9phvkj1.apps.googleusercontent.com", "secret" => "THIS IS SECRET" ),
),
"Facebook" => array(
"enabled" => true,
"keys" => array("id" => "867928933297942", "secret" => "THIS IS SECRET"),
"scope" => "email",
'trustForwarded'=>false
),
"Twitter" => array(
"enabled" => true,
"keys" => array("key" => "siXI8ArTFNmlCkwqIDUxQZSha", "secret" => "THIS IS SECRET")
)
)这是我的登录脚本:
if (isset($_GET['provider'])) {
// the selected provider
$provider_name = $_REQUEST["provider"];
try
{
// initialize Hybrid_Auth class with the config file
$hybridauth = new Hybrid_Auth( '../vendor/hybridauth/hybridauth/hybridauth/config.php' );
// try to authenticate with the selected provider
$adapter = $hybridauth->authenticate( $provider_name );
// then grab the user profile
$user_profile = $adapter->getUserProfile();
}
catch( Exception $e )
{
exit ($e->getMessage()) ;
/*header("Location: ./");*/
}
$user_exist = get_user_by_provider_and_id( $provider_name, $user_profile->identifier );
// print_r($user_exist);
// if the used didn't authenticate using the selected provider before
// we create a new entry on database.users for him
if($user_exist['count']==0 )
{
$user_id_generated =
create_new_hybridauth_user(
$user_profile->email,
$user_profile->firstName,
$user_profile->lastName,
$provider_name,
$user_profile->identifier
);
if ($user_id_generated) {
$userID = $user_id_generated;
}
}else{
$userID = $user_exist['user_id'];
}
// set the user as connected and redirect him
$_SESSION["user"] = $userID;
header('location:/forum');
}//else if (isset($_GET['provider'])) {有人知道解决办法是什么吗?
发布于 2016-07-12 02:48:23
也有同样的问题。确保在Twitter应用程序设置中设置了回调URL。您希望用户在登录后看到的任何页面。
https://stackoverflow.com/questions/31764047
复制相似问题