简体   繁体   English

如何使用 API 在 Google Drive 上创建文件夹和文件? 安卓

[英]How to create a folder and a file on Google Drive using API? Android

I would like to create a folder and a file in Google Drive using Google Drive API in my Android app.我想在我的 Android 应用程序中使用 Google Drive API 在 Google Drive 中创建一个文件夹和一个文件。 I read the document and just give this code:我阅读了文档并给出了以下代码:

    File fileMetadata = new File();
    fileMetadata.setName("Invoices");
    fileMetadata.setMimeType("application/vnd.google-apps.folder");

    File file = driveService.files().create(fileMetadata)
            .setFields("id")
            .execute();
    System.out.println("Folder ID: " + file.getId());

But the editor always wants me to create a local variable of driveService .但是编辑器总是要我创建一个driveService的局部变量。 what is driveService ?什么是driveService the quickstart document seems not a example for android?快速入门文档似乎不是 android 的示例?

Drive Android API is deprecated since December 2018, and you should use the REST API , which contains this quickstart . Drive Android API 自 2018 年 12 月起已弃用,您应使用包含此快速入门REST API

In this case, the driveService corresponds to an instance of Class Drive , and can be used to call the API through the Java library.在这种情况下, driveService对应于Class Drive 的一个实例,可用于通过 Java 库调用 API。

Instantiating Drive requires you to provide credentials .实例化Drive需要您提供credentials You can see a detailed example in the referenced Java quickstart (where driveService is instead named service ), and can see the different ways of doing this, documented in the library docs : see Drive constructor and Drive.Builder .您可以在引用的 Java 快速入门中看到一个详细的示例(其中driveService被命名为service ),并且可以看到执行此操作的不同方法,记录在库文档中:请参阅Drive 构造函数Drive.Builder

Reference:参考:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Google Drive Android API删除Google Drive上的文件 - How to delete a file on google drive using Google Drive Android API 如何使用 Java Google Drive API 创建文件夹动态和上传多个文件 - How to create folder dynamic and upload multiples file using Java Google Drive API 如何使用云端硬盘API连接到Google云端硬盘文件夹 - How to make a connection to a Google Drive folder using the Drive API 如何以编程方式在Google驱动器中的Google驱动器的App文件夹中创建文件夹 - How to Create a Folder in App Folder in google drive in Android Programmatically 如何在根目录中创建文件夹并在Android的Google Drive REST API v3中获取其ID - How to create a folder in root and get its ID in Google Drive REST API v3 in Android 无法使用 REST API 在谷歌驱动器的特定文件夹中上传文件 - Unable to upload file in specific folder in google drive using REST API 如何使用Java和Drive API在Google Drive上创建电子表格 - How to create a Spread Sheet on Google Drive Using Java and Drive API 如何使用drive api java从谷歌驱动器下载文件? - How to download a file from google drive using drive api java? 使用UI Google Drive Android创建文件夹 - Create folder with UI Google Drive Android Android google drive v3 api 文件未创建/存储特定于应用程序的文件夹,而是在我的驱动器部分使用“Untitile”文件名创建 - Android google drive v3 api File is not Created/Store application-specific Folder but instead it create in My drive section with "Untitile" file name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM