【问题标题】:Google API Client - id_token must be passed in or set as part of setAccessTokenGoogle API 客户端 - id_token 必须传入或设置为 setAccessToken 的一部分
【发布时间】:2018-05-18 07:42:47
【问题描述】:

我正在尝试使用我从 Google Developers Playground (OAuth 2.0) 获得的令牌 ID 创建一个返回 google 用户配置文件的 API。我已阅读并遵循指南,但是当我尝试使用我的代码时,它显示id_token must be passed in or set as part of setAccessToken。这是我的代码:

  $id_token = $this->input->post('id_token');
  $id_event = $this->input->post('id_event');

  $client = new Google_Client(['client_id' => GOOGLE_CLIENT_ID]);
  $payload = $client->verifyIdToken($id_token); //It's error here

起初它运行良好,但当我尝试再次运行它时,出现错误。我该怎么办?

这是完整的错误信息:

Type: LogicException
Message: id_token must be passed in or set as part of setAccessToken

Filename: D:\XAMPP\htdocs\api\application\vendor\google\google-api-php-client\src\Google\Client.php
Line Number: 702

Backtrace:
    File: D:\XAMPP\htdocs\api\application\controllers\C_android_api.php
    Line: 190
    Function: verifyIdToken

    File: D:\XAMPP\htdocs\api\index.php
    Line: 315
    Function: require_once

【问题讨论】:

    标签: php oauth-2.0 google-oauth


    【解决方案1】:

    查看我的解决方案here

    当我提供“电子邮件”范围时,修复了以下问题“id_token 必须传入或设置为 setAccessToken 的一部分”。

    $client->addScope("email");

    参考和完整示例:https://github.com/google/google-api-php-client/blob/master/examples/idtoken.php

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2017-01-11
      • 2021-08-02
      • 2018-02-24
      • 2019-02-23
      • 2016-10-22
      • 2017-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多