none
Vb.net authorization (oauth2) google apis RRS feed

  • Question

  • Hi,

    I'm using youtube api and google drive api in my application.

    I'm having troubles with them together, if I ask authorization to drive for 1 hour I can't  ask for youtube authorization.

    How can I ask authoriation for both services(youtube and drive)?

    here some codes that I use to have the token:

    DRIVE:

    Dim MyUserCredential As UserCredential = GoogleWebAuthorizationBroker.AuthorizeAsync(New ClientSecrets() With {.ClientId = GDclientID.Text, .ClientSecret = ClientsecretGD.Text}, {DriveService.Scope.Drive}, "user", Threading.CancellationToken.None).Result
    			service = New DriveService(New BaseClientService.Initializer() With {.HttpClientInitializer = MyUserCredential, .ApplicationName = "DriveApi"})

    YOUTUBE:

    credenYou= Await GoogleWebAuthorizationBroker.AuthorizeAsync(
    					New ClientSecrets With {.ClientId = txtclientid.Text,
    																.ClientSecret = txtclientsecret.Text},
    													 {YouTubeService.Scope.Youtube}, "user", Threading.CancellationToken.None)

    So if I use them single a webpage ask me for authorization and it give me access ony for one scope (youtube or drive) how can I ask access for both services?

    Thanks

    Friday, August 10, 2018 8:52 AM

Answers

  • I just solved in this way.

    Dim array1() As String = {YouTubeService.Scope.Youtube, DriveService.Scope.Drive}
    
    	' Cast the array to IEnumerable reference.
    	Dim reference1 As IEnumerable(Of String) = array1
    
    	' Use an extension method on IEnumerable.
    	Dim scopes As List(Of String) = reference1.ToList()

    Now I have access to youtube and drive. But to much variables declared, do you think exist a simple way to declare them with less code?

    thanks to all

    Friday, August 10, 2018 10:38 AM

All replies

  • Are you using ASP.NET?
    Friday, August 10, 2018 9:52 AM
  • No I'm using vb.net
    Friday, August 10, 2018 9:55 AM
  • I just solved in this way.

    Dim array1() As String = {YouTubeService.Scope.Youtube, DriveService.Scope.Drive}
    
    	' Cast the array to IEnumerable reference.
    	Dim reference1 As IEnumerable(Of String) = array1
    
    	' Use an extension method on IEnumerable.
    	Dim scopes As List(Of String) = reference1.ToList()

    Now I have access to youtube and drive. But to much variables declared, do you think exist a simple way to declare them with less code?

    thanks to all

    Friday, August 10, 2018 10:38 AM
  • No I'm using vb.net

    Of course,  ASP.NET can use VB.NET or C# as the language being used in working with an ASP.NET solution.

    So what you are using is a Windows desktop solution using VB.NET, if you don't know what ASP.NET is about. 

    Friday, August 10, 2018 11:25 AM