【问题标题】:Unable to retrieve an access token for Google's API using google-api-php-client无法使用 google-api-php-client 检索 Google API 的访问令牌
【发布时间】:2017-09-06 02:29:46
【问题描述】:

我正在尝试从 Google API 接收访问令牌:

$client = new Google_Client();        
$client->setAuthConfig('service-account.json');        
$client->setScopes('https://www.googleapis.com/auth/bigquery');        
$client->setSubject($user_to_impersonate);    
var_dump($client->getAccessToken());    

我已经尝试过使用GOOGLE_APPLICATION_CREDENTIALS,但它也返回了null:

$client = new Google_Client();       
putenv('GOOGLE_APPLICATION_CREDENTIALS=service-account.json');        
$client->useApplicationDefaultCredentials();        
$client->setScopes('https://www.googleapis.com/auth/bigquery');        
$client->setSubject($user_to_impersonate);        

【问题讨论】:

  • 我已经清理了你的问题。请更清楚地解释到底出了什么问题。 (例如,您说第二个示例“也返回null”。这是否意味着您的第一个示例中的$client->getAccessTokan() 返回null?service-account.json 中有什么?)请参阅How to Ask。
  • 两种方法都返回NULL
  • 现在我收到另一个错误:致命错误:未捕获的异常 'InvalidArgumentException' 带有消息 'json key is missing the type field' in ........../libraries/google -api-client-/vendor/google/auth/src/CredentialsLoader.php:118 堆栈跟踪
  • 这是我的 json 文件 {"installed": { "client_id":"446624870044-lsouk9hbm941pl29fqa4ip0s3gn65454.apps.googleusercontent.com", "project_id":"e3-gaga-555", "auth_uri" :"accounts.google.com/o/oauth2/auth", "token_uri":"accounts.google.com/o/oauth2/token", "auth_provider_x509_cert_url":"googleapis.com/oauth2/v1/certs" } }
  • 好吧...我看到了正在发生的事情...我的 json 服务帐户已被弃用。我需要再次下载它,所以它在 json 文件中带有更多的 vars...已弃用的只有 3 个字段...

标签: php access-token


【解决方案1】:

好吧...我看到了正在发生的事情...我的 json 服务帐户文件已被弃用。我需要再次下载它,所以它在 json 文件中附带了更多的 vars...已弃用的只有 3 个字段...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-16
    • 1970-01-01
    • 2014-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多