使用VBnet Express的Google云端硬盘

时间:2015-11-04 13:05:45

标签: vb.net google-api google-drive-api google-api-dotnet-client

我在使用VB.net Express 2012连接到Google云端硬盘时遇到问题。 它支持吗?

Imports Google.Apis.Auth.OAuth2
Imports Google.Apis.Drive.v2
Imports Google.Apis.Drive.v2.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
        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")

                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.MaxResults = 10

            ' List files.
            Dim files As IList(Of Google.Apis.Drive.v2.Data.File) = listRequest.Execute().Items
            Console.WriteLine("Files:")
            If files IsNot Nothing AndAlso files.Count > 0 Then
                For Each file As var In files
                    Console.WriteLine("{0} ({1})", file.Title, file.Id)
                Next
            Else
                Console.WriteLine("No files found.")
            End If
            Console.Read()

        End Sub
    End Class
End Namespace

我在控制台中运行Nuget失败了,所以我不得不手动将DLL复制到项目中并将它们作为引用添加,这似乎可以正常工作,因为Imports google.*不再出错,但我得到了代码中的错误。

enter image description here

任何帮助?

更新

我认为问题可能是我正在使用vbnet express 2012 就像https://developers.google.com/drive/web/quickstart/dotnet上所说: 先决条件

要运行此快速入门,您需要:

Visual Studio 2013或更高版本。

有什么工作吗?

UPDATE2

我不再需要此代码,因为我将使用不同的方法 如果其他人有同样的问题,请随时回答

1 个答案:

答案 0 :(得分:0)

对于var错误,看起来像c#。 将其替换为Google.Apis.Drive.v2.Data.File,或者可能只是File,因为它已导入。

用Google.Apis.Util.Store.FileDataStore替换Filedatastore

您没有初始化'服务'正确。这看起来更像是c#。 使用类似的东西: 昏暗的服务如新...... 请参阅:https://msdn.microsoft.com/en-us/library/bb531244.aspx