我有一个服务器应用程序需要读取用户日历的所有日历条目。用户已经授权,我已将authcode和刷新令牌存储在我的服务器数据库中。我可以使用已保存的oauth2令牌初始化日历api v3日历服务吗?如果不在运行时请求用户授权,我无法弄清楚如何使其工作。
我有这个工作,但我无法确定如何使用预定义的令牌来初始化服务。
Dim myscopes As String() = New String() {CalendarService.Scope.Calendar} ' New () {CalendarService.Scope.Calendar}
Dim secrets As New ClientSecrets() With { _
.ClientId = rs.OAuth2Parameters.ClientId, _
.ClientSecret = rs.OAuth2Parameters.ClientSecret _
}
Dim credential As UserCredential = GoogleWebAuthorizationBroker.AuthorizeAsync(secrets, myscopes, "sellggltest1@gmail.com", System.Threading.CancellationToken.None).Result
Dim service = New CalendarService(New BaseClientService.Initializer() With { _
.HttpClientInitializer = credential, _
.ApplicationName = rs.Application _
})
Dim request As CalendarListResource.ListRequest = service.CalendarList.List()
Dim events As Data.CalendarList = request.Execute()