【问题标题】:Google Contacts API: how to reuse authorization code?Google Contacts API:如何重用授权码?
【发布时间】:2015-09-15 17:56:20
【问题描述】:

当我使用以下代码时,我成功获取了联系人:

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() 

我的问题是:

我怎样才能以某种方式跨会话保持授权,这样我就不需要每隔几个小时就要求用户授权访问他的联系人列表?

【问题讨论】:

    标签: .net oauth-2.0 gdata google-contacts-api


    【解决方案1】:

    我们可以使用旧的 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-04
      • 2012-05-06
      • 1970-01-01
      • 2016-11-01
      • 1970-01-01
      • 2011-11-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多