0
我可以通过oauth过程获取我可以成功用于与GDrive进行交互的令牌。令牌具有AccessToken但不具有RefreshToken。我如何获得RefreshToken?Golang Google Drive Oauth2未返回刷新令牌
这是在Web服务中。下面是启动OAuth授权程序代码:
// Set up a configuration.
oauthconfig := &oauth2.Config{
ClientID: XXX,
ClientSecret: XXX,
RedirectURL: "https://MYDOMAIN/gdrivecb",
Scopes: []string{"https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/drive"},
Endpoint: oauth2.Endpoint{
AuthURL: "https://accounts.google.com/o/oauth2/auth",
TokenURL: "https://accounts.google.com/o/oauth2/token",
},
}
url := oauthconfig.AuthCodeURL(MYSCOPEDATA, oauth2.AccessTypeOffline)
http.Redirect(w, r, url, http.StatusFound)
这里的时候/ gdrivecb被称为时调用的相关代码(的OAuthConfig是和以前一样,代码是code
URL参数:
token, err = oauthconfig.Exchange(nil, code)
该令牌包含一个AccessToken但不包含RefreshToken,并且它可以工作一个小时(Expiry的长度),但之后会停止工作。
当检索代码时,需要在URL中包含“access_type = offline”来检索代码。用于检索代码的网址是“https://accounts.google.com/o/oauth2/v2/auth?response_type = code&client_id = ###&redirect_uri = ###我&scope = ###&access_type = offline''详细信息是https://developers.google.com/identity/protocols/OAuth2WebServer – Tanaike
带有oauth2.AccessTypeOffline的AuthCodeURL()函数将“access_type = offline”添加到重定向URL,因此已经发生。 –
对不起,我忍不住。 – Tanaike