我正在尝试为OAuth响应令牌返回OAuth 2响应代码.但是,我的请求返回以下错误,谷歌的结果为零.我尝试更改response_type为"令牌"而不是"代码",但这也不起作用.
OAuth 2参数只能有一个值:response_type
请求详情:
scope=https://www.googleapis.com/auth/userinfo.email
client_secret=_____
response_type=code
grant_type=authorization_code
redirect_uri=http://localhost/folder/
client_id=____.apps.googleusercontent.com
code=_____
Run Code Online (Sandbox Code Playgroud)
我正在发送这个第二步有效载荷 POST https://accounts.google.com/o/oauth2/auth
我的要求有什么问题?
我刚刚意识到https://accounts.google.com/o/oauth2/token应该使用此请求的URL.但是,更改为该URL现在提供:
HTTP/1.0 400 Bad Request
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Fri, 27 Jul 2012 22:44:35 GMT
Content-Type: application/json
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
{
"error" : "invalid_request"
}
Run Code Online (Sandbox Code Playgroud)
response_type如上所述删除和更改URL解决了这个问题.
我正在尝试使用Google的日历API制作应用.我按照这里的指示行事.我可以请求获取授权代码,但我似乎无法形成获取访问令牌的有效请求.我一直得到回应{"error" : "invalid_request"}.这是我正在发出的POST请求:
POST /o/oauth2/token HTTP/1.1
Host: accounts.google.com
Content-Type: application/x-www-form-urlencoded
code=4/vxQqw9JMYEnXvI8A_93OV7kBSg6h.8r2yJUkMc18dshQV0ieZDAraZNwsbwI&
client_id=[my client id]&
client_secret=[my client secret]&
redirect_uri=http://localhost:8080/auth&
grant_type=authorization_code
Run Code Online (Sandbox Code Playgroud)
下面是通过curl调用url的输出.我的实际应用程序是用Node.js编写的,但是我通过应用程序获得了与curl相同的响应.我四处搜寻并看到有类似问题的人,但仍然无法弄清楚我做错了什么.
curl -v -k --header "Content-Type: application/x-www-form-urlencoded" --data-urlencode "code=4/vxQqw9JMYEnXvI8A_93OV7kBSg6h.8r2yJUkMc18dshQV0ieZDAraZNwsbwI&client_id=[my client id]&client_secret=[my client secret]&redirect_uri=http://localhost:8080/auth&grant_type=authorization_code" https://accounts.google.com/o/oauth2/token
* About to connect() to accounts.google.com port 443 (#0)
* Trying 173.194.74.84... connected
* Connected to accounts.google.com (173.194.74.84) port 443 (#0)
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11): …Run Code Online (Sandbox Code Playgroud)