当我使用以下代码时,我成功获取了联系人:
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 :(得分:0)
我们可以使用旧的Access-Token和Refresh-Token(第一次获得)
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)