Google Drive 实施到 Android 应用程序并从 Google Drive 下载文件 [英] Google Drive Implementation to Android app and Downloading the file from Google drive
问题描述
Drive 快速启动应用示例仅适用于将文件从 Android 设备上传到用户帐户.我想将文件从 Gdrive 下载到 Android 应用程序.任何帮助将不胜感激.
Drive Quick-start App example works for only uploading files from Android Device to user account. I want to download the files from Gdrive to android app. any help will be appreciated.
我想要这个演示示例的完全相反的过程 https://developers.google.com/drive/quickstart-android(从 Gdrive 下载)
I want exact reverse process of this Demo example https://developers.google.com/drive/quickstart-android (download it from Gdrive)
推荐答案
从云端硬盘下载文件内容有两个步骤.首先,检索文件的元数据和文件的 downloadUrl:
There are two steps to download file contents from Drive. First, retrieve the file's metadata and a downloadUrl for the file:
// retrieve metadata
File file = drive.files().get(fileId).execute();
然后,向 downloadUrl 发出经过身份验证的请求:
And, make an authenticated request to the downloadUrl:
// download contents a
GenericUrl url = new GenericUrl(file.getDownloadUrl());
HttpResponse response = drive.getRequestFactory().buildGetRequest(url).execute();
String contents = new Scanner(response.getContent()).useDelimiter("\A").next();
这篇关于Google Drive 实施到 Android 应用程序并从 Google Drive 下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!