google api'Google_Service_Plus':无法访问'人民获取'

时间:2014-12-29 23:02:05

标签: php api oauth

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

$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()     {         $这 - > setToken($ _ SESSION [ 'ACCESS_TOKEN']);         $这 - >客户机> verifyIdToken();         $ payload = $ this-> client-> verifyIdToken() - > getAttributes()['payload'] ['email'];         echo $ 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

我错过了什么?

1 个答案:

答案 0 :(得分:1)

WOW! 我需要在https://console.developers.google.com中激活“Google+ API”。

现在有效!