在特定文件夹中创建文件夹GOOGLE DRIVE API V3。

问题描述 投票:-2回答:2

我试图通过编程获得我的google drive中的文件夹名称,并在文件夹内创建一个文件夹,但没有办法。

我已经审查了这个文档。

Google Drive API EXAMPLE!

但我如何得到一个特定的文件夹,并创建另一个吗?

好吧,我需要更新位图到谷歌驱动器。我试图用这个代码,但不工作

        String IdFolder = (String) objects[0];
            Bitmap bitmapUpload = (Bitmap) objects[1];

            File fileMetadata = new File();
            fileMetadata.setTitle("photo.jpg");
            fileMetadata.setParents(Collections.singletonList(new ParentReference().setId(IdFolder)));

            File file = mService.files().insert(fileMetadata, bitmapUpload)
                    .setFields("id, parents")
                    .execute();
            System.out.println("File ID: " + file.getId());

我已经试过了。

            String IdFolder = (String) objects[0];
            Bitmap bitmapUpload = (Bitmap) objects[1];

            int byteSize = bitmapUpload.getRowBytes() * bitmapUpload.getHeight();
            ByteBuffer byteBuffer = ByteBuffer.allocate(byteSize);
            bitmap.copyPixelsToBuffer(byteBuffer);


            byte[] byteArray = byteBuffer.array();


            ByteArrayInputStream bs = new ByteArrayInputStream(byteArray);

            File fileMetadata = new File();
            fileMetadata.setTitle("photo.jpg");
            fileMetadata.setParents(Collections.singletonList(new ParentReference().setId(IdFolder)));

            File file = mService.files().insert(fileMetadata, bs)
                    .setFields("id, parents")
                    .execute();
            System.out.println("File ID: " + file.getId());

但不工作。只是说。

com.google.api.client.http.abstract inputstreamcontent(输入流内容)

?¿?

android google-drive-android-api
2个回答
2
投票

首先要做的是确保你的凭证是有效的。要提出请求的驱动器API,按照指定的指令在。文件的快速启动假设你将使用安卓系统)。然后你可以 处理文件夹 的基础上,根据文件。还要注意的是 parents 在创建文件夹时,也可以使用属性来创建子文件夹。希望能帮到你。


0
投票

我试着做了一个python函数,你可以用你想要的方式使用它。

def create_folder_in_folder(folder_name,parent_folder_id):

    file_metadata = {
    'name' : folder_name,
    'parents' : [folder_id],
    'mimeType' : 'application/vnd.google-apps.folder'
    }

    file = drive_service.files().create(body=file_metadata,
                                    fields='id').execute()

    print ('Folder ID: %s' % file.get('id'))

希望能帮到你。

© www.soinside.com 2019 - 2024. All rights reserved.