我正在尝试使用vb.net使用 Google Drive API 。 我看过很多帖子,但我无法理解如何选择合适的文件夹来添加文件。
我有很多“备份”文件夹,但我现在假设,我想在“MyApp1”文件夹下的“备份”文件夹中添加一个文件。
我这样做,但我不知道如何继续。我搜索了所有“备份”文件夹,我需要检查哪个文件夹位于父文件夹“Myapp”下。
Public Shared Function TheRightFolder() As Boolean
Try
Dim FolderName As String = "Backup"
Dim ParentName As String = "MyAPP1"
Dim result As Boolean = False
Dim request = Service.Files.List()
Dim requeststring As String = ("mimeType='application/vnd.google-apps.folder' And trashed=false and title='" & FolderName & "'")
request.Q = requeststring
Dim Parent = request.Execute()
For Each item As File In Parent.Items
'Get PARENT NAME OF THE FOLDER TO CHECK IF I AM INSERT IN MY FILE IN THE RIGHT DIRECTORY (USING 'item.Parents DATA'?)
'...
If ParentName = new_func_to_get_parent_folder_name Then
Return True
End If
Next
Catch EX As Exception
MsgBox("ERROR" & EX.Message)
End Try
Return False
End Function
我做错了什么?
我是否需要改变思考以获得正确文件夹的方式?
提前致谢!
答案 0 :(得分:1)
您必须共享创建的文件夹。
'Comparte la carpeta creada
Dim userPermission As Permission = New Permission()
userPermission.Type = "anyone"
userPermission.Role = "writer"
Dim request4 = eDRIVEService.Permissions.Create(userPermission, Results2.Files.Item(0).Id.ToString)
request4.Fields = "id"
request4.Execute()
答案 1 :(得分:0)
找到解决方案:
Public Shared Sub ParentsInFolder(ByVal folderId As String)
Dim request As ParentsResource.ListRequest = Service.Parents.List(folderId)
Try
Dim parents As ParentList = request.Execute()
For Each parent As ParentReference In parents.Items
Dim FileId As String = parent.Id.ToString
InfoFromID(Service, FileId)
Next
Catch e As Exception
MsgBox("Errore: " & e.Message)
End Try
End Sub
和
Public Shared Sub InfoFromID(ByVal Service As DriveService, fileId As String)
Try
Dim file As File = service.Files.Get(fileId).Execute
Dim Title As String = file.Title
Dim MimeType As String = file.MimeType.ToString
Dim description As String = file.Description
Catch e As Exception
MsgBox("Errore: " + e.Message)
End Try
End Sub