2012-04-10 46 views
2

我正在使用oauth2(node.js和connect-oauth库)连接到google contacts API version 3.0在Google Contacts API版本3.0上使用oauth2检索刷新标记

这样做,我得到这样的回应:

{ access_token : "...", 
"token_typen": "Bearer", 
"expires_in" : 3600, 
"id_token": "..." } 

我缺少用于令牌只要后者过期得到一个新的接入刷新令牌。

选项的oauth2

{ host: 'accounts.google.com', 
    port: 443, 
    path: '/o/oauth2/token', 
    method: 'POST', 
    headers: 
    { 'Content-Type': 'application/x-www-form-urlencoded', 
    Host: 'accounts.google.com', 
    'Content-Length': 247 } } 

体交 “REDIRECT_URI = HTTP%3A%2F%2Flocalhost%2Foauth2callback & grant_type = authorization_code & CLIENT_ID =客户端ID & client_secret = CLIENTSECRET &类型= web_server &代码= 4 %2F3gbiESZTEOjiyFPLUhKfE_a_jr8Q”

注:我试图从similar question的请求post_body添加approval_prompt =力,但是这导致了n错误

{ statusCode: 400, data: '{\n "error" : "invalid_request"\n}' } 

回答

2

NOTE: I tried to add approval_prompt=force from a similar question to the request-post_body but this resulted in an Error

当你问一个令牌,您不需要approval_prompt PARAM。 * approval_prompt *参数用于授权部分。


I am missing the refresh token...

你没有得到一个* refresh_token *的唯一途径是当:

因此,请尝试向授权码请求添加:access_type=offline

编辑

即:

https://accounts.google.com/o/oauth2/auth?client_id=**your_client_id**&scope=https://www.googleapis.com/auth/plus.me&redirect_uri=http://localhost&response_type=code&access_type=offline 

如果您收到400是因为你要添加一个无效的参数或缺少一个。

祝你好运!

+0

谢谢您的回答。不幸的是,这也不起作用。我收到一个错误:{statusCode:400,data:'{“error”:“invalid_request”}'}。 – forste 2012-04-17 16:29:43

0

有一次我做了这个测试 - 我已经从应用中删除了谷歌授权令牌 - 所以它试图得到另一个,但它没有刷新令牌。

因此,请检查您正在测试未经授权,你是从测试帐号的应用程序(这是否有意义?)

+0

Google只会给您一次刷新令牌。初始认证后,您只能获得令牌。如果您(或您的用户)通过访问https://accounts.google.com/b/0/IssuedAuthSubTokens并从头开始验证序列,则可以获取新的更新令牌。 – HardScale 2014-02-06 03:24:27

相关问题