谷歌API“Google_Service_Plus”:无法访问“人们得到”


google api 'Google_Service_Plus' : cannot access 'people get'

我可以使用谷歌客户端来获取电子邮件,如下所示:

$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';

。 公共函数 getEmail() { $this->setToken($_SESSION['access_token']); $this->client->verifyIdToken(); $payload = $this->client->verifyIdToken()->getAttributes()['payload']['email']; 回声$payload;

。这会与电子邮件相呼应。好。

现在我想使用Google_Service_Plus"people->get",如下所示:

$this->setToken($_SESSION['access_token']);
$this->client->verifyIdToken();
$googlePlus = new Google_Service_Plus($this->client);
$userProfile = $googlePlus->people->get('me');

但是$userProfile返回此错误:

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

我错过了什么?

> 哇!我需要在 https://console.developers.google.com 中激活"Google+ API"。

现在它工作了!