要将社交登录功能添加到网站,我使用的是hybridauth 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'])) {
有谁知道解决方案是什么?
答案 0 :(得分:0)
有同样的问题。确保在Twitter应用设置中设置了回调网址。无论您希望用户在登录后看到什么页面。