【问题标题】:'Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }'' on live site, but works on local environment'刷新 OAuth2 令牌时出错,消息:'{ "error" : "invalid_grant" }'' 在实时站点上,但适用于本地环境
【发布时间】:2015-09-17 01:09:39
【问题描述】:

我在使用 Google Admin SDK 时遇到了一个非常奇怪的问题(我使用的是 Google API PHP 客户端库)。我可以成功添加组和用户,并且通常在我的本地开发机器上使用 API,但是当我将它放在实时网站上时,它会因以下错误而崩溃:

Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }''

我将它与服务帐户结合使用。为此,我生成了一个 p12 密钥和一个我都包含在项目中的客户端 JSON 文件。我也使用真实账户作为委托管理员账户。

我正在使用以下代码连接到 Google SDK:

<?php
$this->client = new Google_Client();
$this->client->setAuthConfigFile(STORAGE_PATH.'client_secrets.json');
$this->client->addScope(static::$scopes);

$cred = new Google_Auth_AssertionCredentials(
    static::$service_account_email,
    static::$scopes,
    file_get_contents(STORAGE_PATH.'TRICS-key.p12'));
$cred->sub = static::$delegated_admin;

$this->client->setAssertionCredentials($cred);

$this->directory_service = new Google_Service_Directory($this->client);

有人知道哪里出了问题吗?

【问题讨论】:

    标签: php google-admin-sdk google-client-login


    【解决方案1】:

    谜团解开了。看来我们的直播环境还有 5 分钟的时间。这导致 OAuth2 身份验证出现问题。因此,如果您有同样的问题,请确保您的时间设置正确,最好是通过 NTP 自动设置!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-26
      相关资源
      最近更新 更多