首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >身份验证失败Twitter时,使用twitter登录时,通过杂交瘤php库

身份验证失败Twitter时,使用twitter登录时,通过杂交瘤php库
EN

Stack Overflow用户
提问于 2015-08-01 16:58:29
回答 1查看 488关注 0票数 0

为了增加网站的社交登录功能,我正在使用杂交 php库开源社交标志。

但是,当我想通过twitter帐户登录到网站时,上面提到的错误信息是显示的,没有任何细节。

“身份验证失败!Twitter返回了一个错误”

我认为所有的脚本和选项都是正确的,但是仍然显示错误。

这是一段config.php文件:

代码语言:javascript
复制
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")
            )
    )

这是我的登录脚本:

代码语言:javascript
复制
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'])) {

有人知道解决办法是什么吗?

EN

回答 1

Stack Overflow用户

发布于 2016-07-12 02:48:23

也有同样的问题。确保在Twitter应用程序设置中设置了回调URL。您希望用户在登录后看到的任何页面。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31764047

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档