2

我已经尝试了几次,但我无法将 Google PlayGround 工具与 Google People API v1 一起使用。

Request / Response
POST /oauth2/v4/token HTTP/1.1
Host: www.googleapis.com
Content-length: 278
content-type: application/x-www-form-urlencoded
user-agent: google-oauth-playground
code=4%2FhQlhA-MiWKhcmHWVUddb8TmiaVEDdMd_3lDHid9eYBc&redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&client_id=111243977462-pc15rhq33ojuc7i54ce3qd8upj6mtnc3.apps.googleusercontent.com&client_secret=ozWubBNz1iKdykitcK757UOo&scope=&grant_type=authorization_code
HTTP/1.1 401 Unauthorized
Content-length: 74
X-xss-protection: 1; mode=block
X-content-type-options: nosniff
Transfer-encoding: chunked
Expires: Sun, 16 Jul 2017 14:54:42 GMT
Vary: Origin, X-Origin
Server: GSE
-content-encoding: gzip
Cache-control: private, max-age=0
Date: Sun, 16 Jul 2017 14:54:42 GMT
X-frame-options: SAMEORIGIN
Alt-svc: quic=":443"; ma=2592000; v="39,38,37,36,35"
Content-type: application/json; charset=UTF-8
Www-authenticate: Bearer realm="https://accounts.google.com/"
{
  "error_description": "Unauthorized", 
  "error": "unauthorized_client"
}

我已经按照以下提示进行操作:

1. Delete the whitespace in the 'OAuth Client ID' and 'OAuth Client secret' in the OAuth 2.0 configuration of Google PlayGround
2. Define in the manager API the authorized redirection URI for: https://developers.google.com/oauthplayground
3. Verify in the Manager API is enabled on the Dashboard

有人可以帮助我提供更多提示以尝试解决问题吗?

下面是我在 Google Playground 上所做的描述:

Step 1 Select & authorize APIs
1. I select Google API v1 and framework https://www.googleapis.com/auth/contacts.readonly
2. Click the 'Authorize APIs'

Step 2 Exchange authorization code for tokens
1. Click the 'Oauth 2.0 Configuration'
2. Click on the 'Use your own OAuth credentials'
3. Enter the 'OAuth Client ID' and the 'OAuth Client secret'
4. Click the button: 'Exchange authorization code for tokens'

我不知道这是否与问题有关,但我注意到连接到我的帐户的应用程序列表没有出现“OAuth 2.0 Playground”。但是我有“Google APIs Explorer”,在那里我成功地测试了对我的联系人的访问(Google People API)。

4

1 回答 1

2

单击齿轮图标转到设置。按照以下定义设置以下内容,然后勾选“使用您自己的 Oauth 凭据”并填写您的 Google OAuth 应用程序的 client_id 和 client_secret:

在您应用的 OAuth 同意屏幕的授权域列表中添加 google.com。

单击要为其配置下一步的应用程序:

确保还在授权的 JavaScript 来源中添加“ https://developers.google.com ”,在授权的重定向 URI 中添加“ https://developers.google.com/oauthplayground ” [添加后单击下面的“保存”]:

然后在选择适当的访问要求后单击“授权 API”:

你应该得到一个提示然后授权它[如果出现安全警告,请继续并单击允许请求的权限]

完成后,您应该有一个授权代码,您可以使用它生成您的令牌[访问令牌和刷新令牌,我们得到一个刷新令牌,因为我们在之前的访问类型设置中指定了“离线”]。这是一次性授权代码[如果你尝试重新使用它,你会得到一个 invalid_grant],存储访问令牌和刷新令牌以与谷歌 API 对话,可以使用刷新令牌生成新的访问令牌。

于 2019-11-06T12:30:41.993 回答