我正在使用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);
}
}
HybridAuth Library位于app文件夹
下的webroot文件夹中然而,我收到的错误是案例6 ,即
案例6:$ error =“用户个人资料请求失败。很可能用户未连接到提供商,他应该再次进行身份验证。”;
确切的错误消息是Undefined variable: adapter [APP\Controller\UsersController.php, line 177]
,它指向CASE 6
任何人都可以提出正在发生的事情。我无法调试它。
P.S。只有使用Google登录
才会发生这种情况此致 枪
答案 0 :(得分:7)
你的问题超过半年,但在这里你解决了问题:
转到https://console.developers.google.com/并激活Google+ API访问权限。
我今天早些时候遇到了这个问题,结果很明显!