英文:
How to create a folder and a file on Google Drive using API? Android
问题
以下是翻译好的部分:
我想在我的Android应用程序中使用Google Drive API在Google Drive中创建一个文件夹和一个文件。
我阅读了文档,只给出了这段代码:
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());
但是编辑器总是要求我创建一个名为driveService
的局部变量。
driveService
是什么?快速入门文档似乎不是针对Android的示例?
英文:
I would like to create a folder and a file in Google Drive using Google Drive API in my Android app.
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
.
what is driveService
? the quickstart document seems not a example for android?
答案1
得分: 2
Drive Android API自2018年12月起已被弃用,您应该使用REST API,其中包含此快速入门。
在这种情况下,driveService
对应于Drive类的一个实例,可用于通过Java库调用API。
实例化Drive
需要您提供credentials
。您可以在引用的Java快速入门中看到详细的示例(其中driveService
改为service
),并且可以在库文档中查看执行此操作的不同方法:请参阅Drive构造函数和Drive.Builder。
参考链接:
英文:
Drive Android API is deprecated since December 2018, and you should use the REST API, which contains this quickstart.
In this case, the driveService
corresponds to an instance of Class Drive, and can be used to call the API through the Java library.
Instantiating Drive
requires you to provide 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.
Reference:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论