Vb.net 如何使用Chilkat DLL从Google驱动器文件夹中获取文件夹ID
我正在使用ChilKat开发一个使用VB.NET的工具,该工具可以将单个文件上传到我的google drive帐户。 我可以在根文件夹中获取文件夹ID,但是如果有文件夹路径,我很难获取文件夹ID 此时,参数FolderPath未被使用(我将在了解如何正确获取FolderID时使用)。目前,我可以获取“Nova”文件夹id,但以下目录树中的其他文件夹都没有: 有没有更简单的方法从Google Drive获取folderID? 我还想在谷歌硬盘上创建文件夹的路径,以防它们不存在 我从未处理过JSON或HTTP请求,所以我在这里有点不知所措。 任何帮助都将不胜感激! 提前谢谢Vb.net 如何使用Chilkat DLL从Google驱动器文件夹中获取文件夹ID,vb.net,winforms,google-drive-api,chilkat,Vb.net,Winforms,Google Drive Api,Chilkat,我正在使用ChilKat开发一个使用VB.NET的工具,该工具可以将单个文件上传到我的google drive帐户。 我可以在根文件夹中获取文件夹ID,但是如果有文件夹路径,我很难获取文件夹ID 此时,参数FolderPath未被使用(我将在了解如何正确获取FolderID时使用)。目前,我可以获取“Nova”文件夹id,但以下目录树中的其他文件夹都没有: 有没有更简单的方法从Google Drive获取folderID? 我还想在谷歌硬盘上创建文件夹的路径,以防它们不存在 我从未处理过JSO
Private Function FolderID(ByVal FolderPath As String) As String
Dim rest As New Chilkat.Rest
' Connect using TLS.
Dim success As Boolean = rest.Connect("www.googleapis.com", 443, True, True)
' Provide the authentication credentials (i.e. the access token)
Dim gAuth As New Chilkat.AuthGoogle
gAuth.AccessToken = M_AccessToken
rest.SetAuthGoogle(gAuth)
Dim json As New Chilkat.JsonObject
json.EmitCompact = False
' Get the folder Testes folder that is in the Google Drive root.
rest.AddQueryParam("q", "'root' in parents and name='Testes'")
Dim jsonResponse As String = rest.FullRequestNoBody("GET", "/drive/v3/files")
If Not rest.LastMethodSuccess Then
Return rest.LastErrorText
Exit Function
End If
json.Load(jsonResponse)
rest.ClearAllQueryParams()
' Now that we know the ID for the Testes directory, get the id for the folder Nova having Testes as the parent.
Dim sbQuery As New Chilkat.StringBuilder
sbQuery.Append("name = 'nova' and '")
sbQuery.Append(json.StringOf("files[0].id"))
sbQuery.Append("' in parents")
rest.AddQueryParamSb("q", sbQuery)
jsonResponse = rest.FullRequestNoBody("GET", "/drive/v3/files")
If Not rest.LastMethodSuccess Then
Return (rest.LastErrorText)
Exit Function
End If
json.Load(jsonResponse)
Return json.StringOf("files[0].id")
End Function
我通过执行迭代请求管理了一种方法。 不知道这是否是正确的方法,但它是有效的 下面是代码,现在使用格式为/folder1/folder2/folderN的FolderPath
Private Function GetFolderID(ByVal FolderPath As String) As String
Dim Rest As New Chilkat.Rest
' Connect to Google APIs server
Dim Connected As Boolean = Rest.Connect("www.googleapis.com", 443, True, True)
If Not Connected Then
Return "Error attempting to connect: " & Rest.ConnectFailReason
Exit Function
End If
' Provide the Access token
Dim GAuth As New Chilkat.AuthGoogle
GAuth.AccessToken = M_AccessToken
Rest.SetAuthGoogle(GAuth)
' Instance to JSON object
Dim JSON As New Chilkat.JsonObject
JSON.EmitCompact = False
' Parse the provided path and split to array
Dim ParseFolder As String = Strings.Right(FolderPath, Len(FolderPath) - 1)
Dim Folders As String() = Split(ParseFolder, "/")
' Get the root folder that is in the Google Drive folders structure
Rest.AddQueryParam("q", "'root' in parents and name='" & Folders(0) & "'")
Dim Response As String = Rest.FullRequestNoBody("GET", "/drive/v3/files")
If Not Rest.LastMethodSuccess Then
Return Rest.LastErrorText
Exit Function
End If
JSON.Load(Response)
'Iterate on the folders to get the last folder's id
Rest.ClearAllQueryParams()
For i = 1 To Folders.Length - 1
Dim sbQuery As New Chilkat.StringBuilder
sbQuery.Append("name = '" & Folders(i) & "' and '")
sbQuery.Append(JSON.StringOf("files[0].id"))
sbQuery.Append("' in parents")
Rest.AddQueryParamSb("q", sbQuery)
Response = Rest.FullRequestNoBody("GET", "/drive/v3/files")
If Not Rest.LastMethodSuccess Then
Return Rest.LastErrorText
Exit Function
End If
JSON.Load(Response)
Next
' Get the folder id
Return JSON.StringOf("files[0].id")
End Function