Google 驱动器 API VB.NET 文件夹的父文件夹

Google Drive API VB.NET Parent Folder of a Folder

我正在尝试使用 Google 驱动器 API 和 vb.net。 看了很多帖子,还是不懂怎么选择合适的文件夹来添加文件。

我有很多 "Backup" 文件夹,但是,我现在假设,我想在 "MyApp1" 文件夹下的 "Backup" 文件夹中添加一个文件。

我正在这样做,但我不知道如何继续。我搜索了我的所有 "Backup" 文件夹,我需要检查哪个在父文件夹 "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

我做错了什么?

我是否需要改变思维方式才能获得正确的文件夹?

提前致谢!

找到解决方案:

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

您必须共享创建的文件夹。

'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()