HybirdAuth用户个人资料请求失败

Gun*_*uns 6 php cakephp hybridauthprovider hybridauth

我正在使用HybridAuth2和CakePHP,我的控制器功能是

public function loginwith($provider) {
        //        $this->autoRender = false;
        require_once( WWW_ROOT . 'hybridauth/Hybrid/Auth.php' );

        $hybridauth_config = array(
            "base_url" => 'http://' . $_SERVER['HTTP_HOST'] . $this->base . "/hybridauth/", // set hybridauth path
            "providers" => array(
                "Google" => array(
                    "enabled" => true,
                    "keys" => array("id" => "clientID", "secret" => "clientSecret")
                )
            )
        );

        try {
            // create an instance for Hybridauth with the configuration file path as parameter
            $hybridauth = new Hybrid_Auth($hybridauth_config);

            // try to authenticate the selected $provider
            $adapter = $hybridauth->authenticate($provider);

            // grab the user profile
            $user_profile = $adapter->getUserProfile();

            debug($user_profile); 
        } catch (Exception $e) {
            // Display the recived error
            switch ($e->getCode()) {
                case 0 : $error = "Unspecified error.";
                    break;
                case 1 : $error = "Hybriauth configuration error.";
                    break;
                case 2 : $error = "Provider not properly configured.";
                    break;
                case 3 : $error = "Unknown or disabled provider.";
                    break;
                case 4 : $error = "Missing provider application credentials.";
                    break;
                case 5 : $error = "Authentification failed. The user has canceled the authentication or the provider refused the connection.";
                    break;
                case 6 : $error = "User profile request failed. Most likely the user is not connected to the provider and he should to authenticate again.";
                    $adapter->logout();
                    break;
                case 7 : $error = "User not connected to the provider.";
                    $adapter->logout();
                    break;
            }

            // well, basically you should not display this to the end user, just give him a hint and move on..
            $error .= "Original error message: " . $e->getMessage();
            $error .= "Trace: " . $e->getTraceAsString();
            $this->set('error', $error);
        }
    }
Run Code Online (Sandbox Code Playgroud)

HybridAuth库位于app文件夹下的webroot文件夹中

但是,我得到这是在错误的情况下6

案例6:$ error ="用户个人资料请求失败.很可能用户没有连接到提供商,他应该再次进行身份验证.";

确切的错误消息是Undefined variable: adapter [APP\Controller\UsersController.php, line 177]指向CASE 6

任何人都可以建议发生了什么.我无法调试这个.

PS仅在Google登录时才会发生这种情况

问候,枪支

Afo*_*mes 8

你的问题超过半年,但在这里你解决了问题:

转到https://console.developers.google.com/并激活Google+ API访问权限.

我今天早些时候遇到了这个问题并且成功了!

  • 没问题.通常我是那个有所有问题但没有答案的人:D (3认同)