我的新项目需要实现 OpenAuth。以下是我的代码。
线
scopes.Add(CalendarService.Scopes.Calendar.GetStringValue())
在 GetAuthorization 中给出以下错误。
重载解析失败,因为没有可访问...
GetStringValue 是这些参数最具体的。我可以理解 GetStringValue 不是在 calendarservice.scopes.calendar 中找到的方法/参数,但我的问题是为什么会这样?我已经从某个网站下载了这段代码,大多数网站都在 C# 中给出示例,但几乎没有任何网站在 VB.Net 中显示任何示例。有人能帮我一下吗。
问候
PS 我正在使用 Visual Studio 2008。
Imports System
Imports System.Diagnostics
Imports DotNetOpenAuth.OAuth2
Imports Google.Apis.Authentication.OAuth2
Imports Google.Apis.Authentication.OAuth2.DotNetOpenAuth
Imports Google.Apis.Calendar.v3
Imports Google.Apis.Util
Imports Google.Apis.Calendar.v3.Data
Imports Google.Apis.Tasks.v1
Imports Google.Apis.Tasks.v1.Data
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim provider = New NativeApplicationClient(GoogleAuthenticationServer.Description)
provider.ClientIdentifier = "Client ID Here"
provider.ClientSecret = "Client Secret Here"
Dim auth = New OAuth2Authenticator(Of NativeApplicationClient)(provider, AddressOf GetAuthorization)
Dim service = New CalendarService(auth)
Dim first = service.CalendarList.List.Fetch().Items().First()
Label1.Text = first.Summary
End Sub
Private Function GetAuthorization(ByVal arg As NativeApplicationClient) As IAuthorizationState
Dim scopes As New System.Collections.Generic.List(Of String)
scopes.Add(CalendarService.Scopes.Calendar.GetStringValue())
Dim state As IAuthorizationState = New AuthorizationState(scopes)
state.Callback = New Uri(NativeApplicationClient.OutOfBandCallbackUrl)
Dim authUri As Uri = arg.RequestUserAuthorization(state)
Process.Start(authUri.ToString())
' Open a modal dialogue for user to paste the authorization code from Browser = authCode
Dim authCode As String = Console.ReadLine()
Return arg.ProcessUserAuthorization(authCode, state)
End Function
End Class