$service->people->get('me') 抛出错误:'Access not Configured'



这里缺少什么?在我的应用程序引擎项目中,我已经将适用于PHP的Google API客户端库上传到服务器。我使用的app.php从以下内容开始:

  require_once 'Google/Client.php';
  require_once 'Google/Service/Plus.php';
  $client = new Google_Client();
  $client->setApplicationName("ApplicationName");
  $client->setDeveloperKey("APP_KEY");
  $service = new Google_Service_Plus($client);
  $me = $service->people->get('me');
  print "ID: {$me['id']}n";

然而,我得到的唯一结果是:

Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling GET https://www.googleapis.com/plus/v1/people/me?key...
Access Not Configured. Please use Google Developers Console to activate the API for your project.' in /base/data/home/apps/...

如果我将其扩展为:

  require_once 'Google/Client.php';
  require_once 'Google/Service/Plus.php';
  $client = new Google_Client();
  $client->setClientId('CLIENT_ID');
  $client->setClientSecret('CLIENT_SECRET');
  $client->setApplicationName("projectName");
  $client->setDeveloperKey("DEVELOPER_KEY");
  $service = new Google_Service_Plus($client);
  $client->setScopes("https://www.googleapis.com/auth/plus.login");
  $me = $service->people->get('me');
  print "ID: {$me['id']}n";

我收到错误消息:...Invalid Credentials'...

显然,我做的第一件事就是在我的开发者控制台中激活Google+API。为什么它仍然抛出错误?尽管运行该脚本后,PHP的登录脚本功能完美。

如果这个问题很明显,很抱歉,但除了在开发人员控制台中激活了API外,您是否更改了代码中的应用程序名称和API密钥?

$client->setApplicationName("ApplicationName");
$client->setDeveloperKey("APP_KEY");

您可以在API&auth->凭据在您的项目控制台中https://console.developers.google.com

相关内容

最新更新