使用 Postman 访问 OAuth 2.0 Google API

2023-12-08

我正在尝试访问邻近谷歌API using 邮递员 Chrome 应用程序。我已按照邮递员和谷歌开发网站上的教程进行操作,但仍然收到 401 错误消息。

我在做什么?

  • 第 1 步 - 启用 Proximity API:

为了使用 Proximity API,必须首先在 Google Dev 控制台中启用它。 使用this教程 我已为我的项目启用了对 Proximity API 的支持

  • 第 2 步 - 获取凭据:

根据this教程,我需要获取客户端 ID 和秘密。这就是我困惑的地方。凭据 -> 添加凭据 -> OAuth2.0 客户端 ID -> 选择 Chrome 应用程序单选按钮(因为我使用的是 Postman)-> 输入 Postman 的 Chrome Web 商店 URL 的最后一部分 [即fhbjgbiflinjbdggehcddcbncdddomop]->点击创建按钮这些步骤只会生成客户端ID,而不是秘密..我做错了什么吗?

From the Google Dev console, one can download an JSON file which has client id, auth URI and Token URI enter image description here

我下载了这个,但如果我使用 Postman,这没什么帮助。我猜测这个 JSON 文件可以包含在 JS 应用程序中。

  • 第 3 步 - 使用 Postman 测试 API

enter image description here

What am I getting? enter image description here

而且,一旦我单击调试 URL,我就会看到以下屏幕

enter image description here


Postman 将查询模拟 Web 应用程序的 Google API

生成 OAuth 2.0 令牌:

  1. 确保 Google API 已启用
  2. 创建 OAuth 2.0 客户端 ID

    • Go to Google Console -> API -> OAuth consent screen
      • Add getpostman.com到授权域。单击“保存”。
    • Go to Google Console -> API -> Credentials
      • Click 'Create credentials' -> OAuth client ID -> Web application
        • 名称:'getpostman'
        • 授权重定向 URI:https://www.getpostman.com/oauth2/callback
    • 复制生成的Client ID and Client secret供以后使用的字段
  3. 在 Postman 中选择授权选项卡并选择“OAuth 2.0”类型。单击“获取新的访问令牌”

    • Fill the GET NEW ACCESS TOKEN form as following
      • 令牌名称:“Google OAuth getpostman”
      • 授权类型:“授权代码”
      • 回调网址:https://www.getpostman.com/oauth2/callback
      • 验证网址:https://accounts.google.com/o/oauth2/auth
      • 访问令牌网址:https://accounts.google.com/o/oauth2/token
      • 客户编号:Client ID在步骤 2 中生成(例如“123456789012-abracadabra1234546789blablabla12.apps.googleusercontent.com”)
      • 客户秘密:Client secret在步骤 2 中生成(例如,“ABRACADABRAus1ZMGHvq9R-L”)
      • 范围:请参阅 Google 文档了解所需的 OAuth 范围(例如,https://www.googleapis.com/auth/cloud-platform)
      • 状态:空
      • 客户端身份验证:“作为基本身份验证标头发送”
    • 单击“请求令牌”和“使用令牌”
  4. 根据 Google 文档设置请求的方法、参数和正文
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Postman 访问 OAuth 2.0 Google API 的相关文章

随机推荐