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

huangapple go评论111阅读模式
英文:

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:

huangapple
  • 本文由 发表于 2020年9月13日 20:23:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/63870732.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定