问题描述
我正在尝试使用
我下载了这个,但如果我使用 Postman,这没什么帮助.我猜这个 JSON 文件可以包含在 JS 应用程序中.
- 第 3 步 - 使用 Postman 测试 API
我得到了什么?
而且,一旦我点击调试 URL,我就会看到以下屏幕
Postman 将模拟 Web 应用程序查询 Google API
生成 OAuth 2.0 令牌:
- 确保启用了 Google API
创建 OAuth 2.0 客户端 ID
- 转到 Google 控制台 -> API -> OAuth 同意屏幕
- 将
getpostman.com
添加到授权域.点击保存.
- 将
- 转到 Google 控制台 -> API -> 凭据
- 单击创建凭据"-> OAuth 客户端 ID -> Web 应用程序
- 名称:'getpostman'
- 授权的重定向 URI:
https://www.getpostman.com/oauth2/callback
- 单击创建凭据"-> OAuth 客户端 ID -> Web 应用程序
- 复制生成的
Client ID
和Client secret
字段以备后用
- 转到 Google 控制台 -> API -> OAuth 同意屏幕
在 Postman 中选择授权选项卡并选择OAuth 2.0"类型.点击获取新的访问令牌"
- 填写获取新访问令牌表格如下
- 令牌名称:'Google OAuth getpostman'
- 授权类型:授权码"
- 回调网址:
https://www.getpostman.com/oauth2/callback
- 验证网址:
https://accounts.google.com/o/oauth2/auth
- 访问令牌网址:
https://accounts.google.com/o/oauth2/token
- 客户端 ID:在步骤 2 中生成的
客户端 ID
(例如,'123456789012-abracadabra1234546789blablabla12.apps.googleusercontent.com') - Client Secret:在第 2 步中生成的
Client secret
(例如,'ABRACADABRAus1ZMGHvq9R-L') - 范围:请参阅 Google 文档以了解所需的 OAuth 范围(例如,https://www.googleapis.com/auth/cloud-platform)
- 状态:空
- 客户端身份验证:作为基本身份验证标头发送"
- 点击请求令牌"和使用令牌"
- 填写获取新访问令牌表格如下
- 根据 Google 文档设置请求的方法、参数和正文
I am trying to access Proximity Google API using Postman chrome app. I have followed tutorials on postman and google dev website but I'm still getting 401 error message.
What am I doing?
- Step 1 - Enable Proximity API:
In order to use Proximity API, it has to be first enabled in Google Dev console.Using this tutorial I have enabled support for Proximity API for my project
- Step 2 - Get the credentials:
According to this tutorial, I need to get client ID and secret. This is where I am confused. Credentials->Add credentials->OAuth2.0 client ID->select Chrome App radio button (since I am using Postman)->enter last part of Postman's Chrome Web store URL [which is fhbjgbiflinjbdggehcddcbncdddomop]->hit create button These steps will only generate a client ID, not a secret..am I doing something wrong?
From the Google Dev console, one can download an JSON file which has client id, auth URI and Token URI
I downloaded this but this is of little help if I am using Postman. I am guessing this JSON file is something that can be included in a JS application.
- Step 3 - Use Postman to test the API
What am I getting?
And, once I click on the debug URL, I see the following screen
Postman will query Google API impersonating a Web Application
Generate an OAuth 2.0 token:
- Ensure that the Google APIs are enabled
Create an OAuth 2.0 client ID
- Go to Google Console -> API -> OAuth consent screen
- Add
getpostman.com
to the Authorized domains. Click Save.
- Add
- Go to Google Console -> API -> Credentials
- Click 'Create credentials' -> OAuth client ID -> Web application
- Name: 'getpostman'
- Authorized redirect URIs:
https://www.getpostman.com/oauth2/callback
- Click 'Create credentials' -> OAuth client ID -> Web application
- Copy the generated
Client ID
andClient secret
fields for later use
- Go to Google Console -> API -> OAuth consent screen
In Postman select Authorization tab and select "OAuth 2.0" type. Click 'Get New Access Token'
- Fill the GET NEW ACCESS TOKEN form as following
- Token Name: 'Google OAuth getpostman'
- Grant Type: 'Authorization Code'
- Callback URL:
https://www.getpostman.com/oauth2/callback
- Auth URL:
https://accounts.google.com/o/oauth2/auth
- Access Token URL:
https://accounts.google.com/o/oauth2/token
- Client ID:
Client ID
generated in the step 2 (e.g., '123456789012-abracadabra1234546789blablabla12.apps.googleusercontent.com') - Client Secret:
Client secret
generated in the step 2 (e.g., 'ABRACADABRAus1ZMGHvq9R-L') - Scope: see the Google docs for the required OAuth scope (e.g., https://www.googleapis.com/auth/cloud-platform)
- State: Empty
- Client Authentication: "Send as Basic Auth header"
- Click 'Request Token' and 'Use Token'
- Fill the GET NEW ACCESS TOKEN form as following
- Set the method, parameters, and body of your request according to the Google docs
这篇关于使用 Postman 访问 OAuth 2.0 Google API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!