Reputation: 3552
I can use google client to get the email, like this :
$this->client->setClientId('...');
$this->client->setClientSecret('...');
$this->client->setRedirectUri('...');
$this->client->setScopes('email');
$this->client->addScope('https://www.googleapis.com/auth/plus.login');
$this->client->setDeveloperKey('...');
$this->client->setAccessType = 'offline';
... public function getEmail() { $this->setToken($_SESSION['access_token']); $this->client->verifyIdToken(); $payload = $this->client->verifyIdToken()->getAttributes()['payload']['email']; echo $payload;
... This echoes the email. Good.
Now I want to use Google_Service_Plus 'people->get', like this :
$this->setToken($_SESSION['access_token']);
$this->client->verifyIdToken();
$googlePlus = new Google_Service_Plus($this->client);
$userProfile = $googlePlus->people->get('me');
But $userProfile returns this error :
Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling GET https://www.googleapis.com/plus/v1/people/me?key=AIzaSyDvOsKSpSKmzVYV6m4tqZ5zHs8GIMdUv9s: (403) Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration.' in C:\xampp\htdocs\phpacademy\googleauth\vendor\google\src\Google\Http\REST.php on line 111
What am I missing ?
Upvotes: 1
Views: 2003
Reputation: 3552
WOW! I needed to activate the 'Google+ API' in https://console.developers.google.com.
Now it works!
Upvotes: 1