OAuth 2.0游乐场:未授权的客户端

4

我尝试了多次,但是我无法使用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)。

1个回答

3

通过点击齿轮图标进入设置。按以下方式设置,然后选中“使用您自己的Oauth凭据”并填写Google OAuth应用程序的client_id和client_secret:

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

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

确保还将 'https://developers.google.com' 添加到已授权的JavaScript起源,并将 'https://developers.google.com/oauthplayground' 添加到已授权的重定向URI [添加后单击“保存”]:

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

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

完成后,您应该有一个授权代码,可以使用它生成您的令牌[访问令牌和刷新令牌,我们在先前的访问类型设置中指定“离线”所以我们获得了一个刷新令牌]。这是一次性授权代码[如果尝试重新使用它,则会收到无效授予提示],请存储访问令牌和刷新令牌以用于与Google APIs进行通信,可以使用刷新令牌生成新的访问令牌。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接