(403) Legacy People API > has not been used before in project XXXXXXXX or is disabled in Codeigniter
<p>I'm using Google login and it was working fine a few months ago, but now when I try to log in it gives the following error: </p>
<blockquote>
<p>Uncaught exception type encountered: Google_Service_Exception</p>
<p>Message: Error while calling GET
https://www.googleapis.com/plus/v1/people/me: (403) Old version of People API
Not previously used in project XXXXXXXX or disabled. enable
access it via
https://console.developers.google.com/apis/api/legacypeople.googleapis.com/overview?project=XXXXXXXX
Then try again. If you recently enabled this API, please wait a few minutes
propagate to our system and retry the operation.</p>
</blockquote>
<p>Visit the link it displays</p>
<pre class="brush:php;toolbar:false;">"Failed to load."
"There was an error while loading /apis/....googleapis.com/overview?project=<project_id>. Please try again."</pre>
<p>I also enabled the <code>People API</code></p>
<p>But still getting the same error message</p>
<p>I have enabled the API: </p>
<p>Please provide any solution, thank you</p>
<p>Code:</p>
<pre class="brush:php;toolbar:false;"><?php
require_once('Google/autoload.php');
class Google {
protected $CI;
public function __construct($url){
$this->CI =& get_instance();
$this->CI->load->library('session');
$this->CI->config->load('google_config');
$this->client = new Google_Client();
$this->client->setClientId($this->CI->config->item('google_client_id'));
$this->client->setClientSecret($this->CI->config->item('google_client_secret'));
$this->client->setRedirectUri($url[0]);
$this->client->setScopes(array(
"https://www.googleapis.com/auth/plus.login",
"https://www.googleapis.com/auth/plus.me",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile"
)
);
}
public function get_login_url(){
return $this->client->createAuthUrl();
}
public function validate(){
if (isset($_GET['code'])) {
$this->client->authenticate($_GET['code']);
$_SESSION['access_token'] = $this->client->getAccessToken();
}
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$this->client->setAccessToken($_SESSION['access_token']);
$plus = new Google_Service_Plus($this->client);
$person = $plus->people->get('me');
$info['id']=$person['id'];
$info['email']=$person['emails'][0]['value'];
$info['name']=$person['displayName'];
$info['link']=$person['url'];
$info['profile_pic']=substr($person['image']['url'],0,strpos($person['image']['url'],"?sz=50")) . '?sz=800';
return $info;
}
}
}</pre>
<blockquote>
<p>GoogleConfig.php</p>
</blockquote>
<pre class="brush:php;toolbar:false;">$config['google_client_id']="XXXXX.apps.googleusercontent.com";
$config['google_client_secret']="XXXX";</pre>
<p>控制器:</p>
<pre class="brush:php;toolbar:false;">$this->load->library('google',array(base_url().$this->config->item('google_redirect_url_signin')));
$this->data['google_redirect_url_signin']=$this->google->get_login_url();</pre>
<p>查看:</p>
<pre class="brush:php;toolbar:false;"><button onclick="location.href ='<?=$google_redirect_url_signin?>';" class="loginBtn loginBtn--google">
Login with Google
</button></pre></p>