2013-02-12 35 views
0

我的新項目需要實現OpenAuth。以下是我的代碼。DotNetOpenAuth2與VB.Net錯誤

在GetAuthorization線

scopes.Add(CalendarService.Scopes.Calendar.GetStringValue()) 

提供了以下錯誤。

重載決策失敗,因爲沒有可訪問...

向GetStringValue是最具體的這些說法。我可以理解,GetStringValue不是在calendarservice.scopes.calendar中找到的方法/參數,但我的問題是爲什麼呢?我從某個網站下載了這個代碼,大多數網站都給出了C#的例子,但幾乎沒有任何網站在VB.Net中顯示任何示例。有人能幫我一下嗎。

Regards

P.S.我正在使用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 

回答

0

GetStringValue是在Google.Apis.Util.Utilities上定義的擴展方法。

類似的VB.NET代碼可以幫助我在VS2012上使用最新版本的庫。 你可以在https://codereview.appspot.com/7007048/找到我的VB.NET示例,但它仍然沒有被批准,所以要小心使用它。

在示例存儲庫(http://code.google.com/p/google-api-dotnet-client/source/browse/?repo=samples#hg%2FDiscovery.VB.ListAPIs)中,目前只有一個VB.NET示例,但希望上面的示例很快就會被批准並將其添加到存儲庫。

請詳細說明您在項目中的參考資料和堆棧跟蹤。 看起來您的代碼或引用程序集中有另一個重載到此GetStringValue的其他位置(http://msdn.microsoft.com/en-us/library/2hx4ayzs(v=vs.80).aspx)。

+0

我無法導入'** Google.Apis.Util.Utilities。**'您是否有任何想法可以爲此導入哪個文件? – 2013-02-14 10:19:40