문제

My new project demands the implementation OpenAuth. Following is my code.

The line

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

in the GetAuthorization gives the following error.

Overload resolution failed because no accessible...

GetStringValue is the most specific for these argument. I can understand that GetStringValue is not the method/argument found in the calendarservice.scopes.calendar but my question is why so? I have downloaded this code from some website and most website is giving example in C# but there are hardly any site that is showing any example in VB.Net. Can anyone help me here.

Regards

P.S. I am using 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
도움이 되었습니까?

해결책

GetStringValue is en extension method defined on Google.Apis.Util.Utilities.

Similar VB.NET code to this worked for me on VS2012 with the latest version of the library. You can find my VB.NET sample in https://codereview.appspot.com/7007048/, but it still wasn't approved, so be careful using it.

In the samples repository (http://code.google.com/p/google-api-dotnet-client/source/browse/?repo=samples#hg%2FDiscovery.VB.ListAPIs), there is currently only one VB.NET sample, but hopefully the sample above will be approved soon and it will be added to the repository.

Please elaborate more on the references that you have in your project and the stack trace. It looks like there is another overloading to this GetStringValue somewhere else (http://msdn.microsoft.com/en-us/library/2hx4ayzs(v=vs.80).aspx) in your code or in a reference assembly.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top