Imports Google.Apis.Auth.OAuth2
Imports Google.Apis.Drive.v3
Imports Google.Apis.Drive.v3.Data
Imports Google.Apis.Services
Imports Google.Apis.Util.Store
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports System.Text
Imports System.Threading
Imports System.Threading.Tasks
Namespace DriveQuickstart
Class Program
' If modifying these scopes, delete your previously saved credentials
' at ~/.credentials/drive-dotnet-quickstart.json
Shared Scopes As String() = {DriveService.Scope.DriveReadonly}
Shared ApplicationName As String = "Drive API .NET Quickstart"
Private Shared Sub Main(args As String())
Dim credential As UserCredential
Using stream = New FileStream("client_secret.json", FileMode.Open, FileAccess.Read)
Dim credPath As String = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal)
credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart.json")
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, New FileDataStore(credPath, True)).Result
Console.WriteLine(Convert.ToString("Credential file saved to: ") & credPath)
End Using
' Create Drive API service.
Dim service = New DriveService(New BaseClientService.Initializer() With { _
Key .HttpClientInitializer = credential, _
Key .ApplicationName = ApplicationName _
})
' Define parameters of request.
Dim listRequest As FilesResource.ListRequest = service.Files.List()
listRequest.PageSize = 10
listRequest.Fields = "nextPageToken, files(id, name)"
' List files.
Dim files As IList(Of Google.Apis.Drive.v3.Data.File) = listRequest.Execute().Files
Console.WriteLine("Files:")
If files IsNot Nothing AndAlso files.Count > 0 Then
For Each file As var In files
Console.WriteLine("{0} ({1})", file.Name, file.Id)
Next
Else
Console.WriteLine("No files found.")
End If
Console.Read()
End Sub
End Class
End Namespace