Google联系人API:如何重复使用授权码?
Google Contacts API: how to reuse authorization code?
我使用以下代码成功获取联系人:
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()
我的问题是:
我怎样才能以某种方式保持跨会话的授权,这样我就不需要每隔几个小时就要求用户授权访问他的联系人列表?
我们可以使用旧的 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)
我使用以下代码成功获取联系人:
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()
我的问题是:
我怎样才能以某种方式保持跨会话的授权,这样我就不需要每隔几个小时就要求用户授权访问他的联系人列表?
我们可以使用旧的 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)