如何在 Android Studio 上连接 Google Drive 以创建文件夹或文件?

How to connect Google Drive on Android Studio for create a folder or file?

我想连接到 Android studio 中的 Google 驱动器 API 并创建一个文件并读取该文件,但我无法连接,即使我有 apiKey。如果我正在调试,则应用程序会在 GoogleApiClient.connect 后关闭。我一直在研究各种页面,但其中一些还采用 SHA1 指纹,这有必要吗?我做错了什么?

遵循 Drive API Android Quickstart

中的设置
  1. 安装 Android SDK.
  2. 下载并配置 Google Play services SDK,其中包括 Google 驱动器 Android API。
  3. 注册您的应用程序。为此,您需要在 Google API 控制台中注册一个项目并为您的应用程序获取签名证书。
  4. required settings 添加到您的应用程序清单中。
  5. 将云端硬盘服务添加到您的应用程序。最简单的开始方法是创建一个文件。

Creating files

You can create files in two ways with the Drive Android API: using the CreateFileActivityBuilder class, or using the createFile() method of the DriveFolder interface. The end result of either approach is the same. However, for instances where the user is specifying the location or title of the file, CreateFileActivityBuilder simplifies the process by providing a premade user interface. To create files programmatically or allow users to specify other metadata in a custom UI activity, you must use the the createFile() method.

Create a folder in the root folder

To create a folder, call DriveFolder.createFolder for the root folder. Pass the metadata containing the title and other attributes to set the values for the folder.

Create folder in Drive REST API

In the Drive API, a folder is essentially a file — one identified by the special folder MIME type application/vnd.google-apps.folder. You can create a new folder by inserting a file with this MIME type and a folder title. Do not include an extension when setting a folder title.