2015-06-29 110 views
0

我成功地得到,當我使用下面的代碼聯繫人:Google Contacts API:如何重用授權碼?

Dim parameters = New OAuth2Parameters() 
parameters.ClientId = "XXX.apps.googleusercontent.com" 
parameters.ClientSecret = "XXXX" 
parameters.RedirectUri = "urn:ietf:wg:oauth:2.0:oob" 
parameters.Scope = "https://www.google.com/m8/feeds" 

Dim authorizationUrl As String = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters) 
Process.Start(authorizationUrl) 
Dim authCode As String = InputBox("Authorisation code", "Authorisation Code", "") 
parameters.AccessCode = authCode 

OAuthUtil.GetAccessToken(parameters) 
Dim accessToken = parameters.AccessToken 

Dim settings = New RequestSettings("my app name") 
Dim cr = New ContactsRequest(settings) 
Dim contcts = cr.GetContacts() 

我的問題是:

我如何能以某種方式在會話中保持的授權,所以我不需要詢問用戶每幾個小時授權訪問他的聯繫人列表?

回答

0

我們可以使用舊的訪問令牌的刷新令牌(即在第一時間拿到)

Dim parameters = New OAuth2Parameters() 
parameters.ClientId = "XXXXX.apps.googleusercontent.com" 
parameters.ClientSecret = "XXXXXX" 
parameters.RedirectUri = "urn:ietf:wg:oauth:2.0:oob" 
parameters.Scope = "https://www.google.com/m8/feeds" 
parameters.ResponseType = "code" 
parameters.AccessToken = "", /* use the value returned from the old call to GetAccessToken here */ 
parameters.RefreshToken = "", /* use the value returned from the old call to GetAccessToken here */ 

OAuthUtil.RefreshAccessToken(parameters)