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