我正在尝试为facebook实施HybridAuth登录。但是它一直给我上面的错误。我尝试在发生此错误后再次将用户重定向到facebook登录页面,但这会导致循环。
请帮帮我。这是我的代码。
public function login($provider)
{
try
{
$this->load->model('home_model');
$this->load->library('HybridAuthLib');
if ($this->hybridauthlib->providerEnabled($provider))
{
$this->service = $this->hybridauthlib->authenticate($provider);
if ($this->service->isUserConnected())
{
$user_profile = $this->service->getUserProfile(); <-- error here
$access_credentials = $this->service->getAccessToken();
redirect("site.com/profile/".$user_profile->identifier,"refresh");
} else { // Cannot authenticate user
show_error('Cannot authenticate user');
}
}
}
catch(Exception $e)
{
$error = 'Unexpected 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 : log_message('debug', 'controllers.HAuth.login: Authentification failed. The user has canceled the authentication or the provider refused the connection.');
//redirect();
if (isset($service)){
$service->logout();
}
break;
case 6 : $error = 'User profile request failed. Most likely the user is not connected to the provider and he should to authenticate again.';
break;
case 7 : $error = 'User not connected to the provider.';
break;
}
if (isset($service))
{
$service->logout();
}
show_error($error);
/* redirect("www.facebook.com/dialog/oauth/?
client_id=[APP_ID]
&redirect_uri=site.com/hauth/login/Facebook
&state=1
&scope=publish_stream
","refresh");* <-- when try to use this. It generates a redirect loop from facebook to my site
}
}