eydjey / google-api-dotnet-client

Automatically exported from code.google.com/p/google-api-dotnet-client
Apache License 2.0
0 stars 0 forks source link

VB Samples for OAuth2 #187

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Which Google API and version (e.g. Google Tasks API version 1)?

Google Calendar API v3

What should the sample demonstrate (e.g. using OAuth2, using a specific
feature of that API)?

OAuth2

Platform (e.g. Windows, Mono, Silverlight, WP7)?

Windows VB .NET

Please provide any additional information below.

The .cs examples provided do not work in VB:

Imports System.Diagnostics
Imports DotNetOpenAuth.OAuth2
Imports Google.Apis.Authentication
Imports Google.Apis.Authentication.OAuth2
Imports Google.Apis.Authentication.OAuth2.DotNetOpenAuth
Imports Google.Apis.Calendar.v3
Imports Google.Apis.Calendar.v3.Data
Imports Google.Apis.Util

...

    Public Shared Sub Main(args As String())

        Dim provider = New NativeApplicationClient(GoogleAuthenticationServer.Description)
        provider.ClientIdentifier = "YOUR_CLIENT_ID"
        provider.ClientSecret = "YOUR_CLIENT_SECRET"
        Dim auth = New OAuth2Authenticator(Of NativeApplicationClient)(provider, AddressOf GetAuthorization)

        Dim service = New CalendarService(auth)
...

    End Sub

    Private Shared Function GetAuthorization(arg As NativeApplicationClient) As IAuthorizationState

        Dim state As IAuthorizationState = New AuthorizationState(New () {CalendarService.Scopes.Calendar.GetStringValue()})
        state.Callback = New Uri(NativeApplicationClient.OutOfBandCallbackUrl)
        Dim authUri As Uri = arg.RequestUserAuthorization(state)

        Process.Start(authUri.ToString())
        Console.Write("  Authorization Code: ")
        Dim authCode As String = Console.ReadLine()
        Console.WriteLine()

        Return arg.ProcessUserAuthorization(authCode, state)
    End Function

Original issue reported on code.google.com by gcaltool...@gmail.com on 18 Feb 2012 at 7:22

GoogleCodeExporter commented 9 years ago
I'm also trying to use this example but I cannot compile. Visual Studio 2010 
has an issue with the extension method: 
CalendarService.Scopes.Calendar.GetStringValue()

The error I get is: The call is ambiguous between the following methods or 
properties: 'Google.Apis.Util.Utilities.GetStringValue(System.Enum)' and 
'Google.Apis.Util.Utilities.GetStringValue(System.Enum)'

Any ideas on how to resolve this?

Original comment by christia...@gmail.com on 22 Feb 2012 at 3:48

GoogleCodeExporter commented 9 years ago
Hi, any idea in VB.NET about use with Refresh Token?? Tonino

Original comment by faz...@gmail.com on 24 Feb 2012 at 11:31

GoogleCodeExporter commented 9 years ago
Try removing Google.Apis.Silverlight from reference list.

Original comment by sahin...@gmail.com on 5 Mar 2012 at 11:17

GoogleCodeExporter commented 9 years ago
I finally got this all working... try this:  

        Dim getAuth As Func(Of NativeApplicationClient, IAuthorizationState) = AddressOf GetAuthorization
        Dim auth As New OAuth2Authenticator(Of NativeApplicationClient)(provider, getAuth)     

Be careful if you enable breakpoints anywhere in the GetAuthorization function 
(on VS 2011) because this can cause the function not to be called as expected...

And try this for scopes:

        Dim scopes As New System.Collections.Generic.List(Of String)
        scopes.Add(CalendarService.Scopes.Calendar.GetStringValue())

        Dim state As IAuthorizationState = New AuthorizationState(scopes)
 ...

I hope this helps, there's quite a few .NET examples in the new Calendar docs 
that are either just plain wrong, or don't convert easily into VB.

Original comment by notesand...@gmail.com on 6 Mar 2012 at 11:16

GoogleCodeExporter commented 9 years ago
I'm struggling with the v3 Calendar API - I just can't find enough information 
to get started.  I've played with the Task and URL Shortener examples, but I 
can't transfer any of what I learned to do anything with Calendar.

Anyone know where I can find any complete example for Calendar that I can use 
to get started?  

Comment 4 above mentions the new Calendar docs, but everything that I've found 
shows just a few lines of code at a time - not enough for me to make sense of 
it.

Any help or pointers to help would be greatly appreciated.

Original comment by bgrayS...@gmail.com on 12 Mar 2012 at 3:45

GoogleCodeExporter commented 9 years ago

Original comment by davidwat...@google.com on 3 Apr 2012 at 6:46

GoogleCodeExporter commented 9 years ago
I'm in the same boat with not being able to find good Calendar v3 
documentation.  The documentation that Google provides does not even compile 
with the v3 libraries.  

Getting pretty frustrated that a company that is trying to get people to use 
its services does not even provide good examples of how to do it.  E.x. 
https://developers.google.com/google-apps/calendar/instantiate under .NET.

Original comment by smatossi...@gmail.com on 19 Apr 2012 at 6:20

GoogleCodeExporter commented 9 years ago

Original comment by asky...@google.com on 25 Apr 2012 at 5:17