【问题标题】:Android upload/download text files from sdcard to Google Drive with Google Play ServicesAndroid 使用 Google Play 服务将文本文件从 sdcard 上传/下载到 Google Drive
【发布时间】:2023-03-23 05:06:01
【问题描述】:

我想使用 Google Play 服务将 Google Drive 上传/下载 txt 文件到我的 Android 应用程序,但我没有找到正确的方法。

在 Dropbox 中很容易:

File file = new File("working-draft.txt");
FileInputStream inputStream = new FileInputStream(file);
Entry response = mDBApi.putFile("/magnum-opus.txt", inputStream,
                            file.length(), null, null);
Log.i("DbExampleLog", "The uploaded file's rev is: " + response.rev);

但是对于带有 Google Play 服务的 Google Drive,我还没有找到这样简单的方法。你知道怎么做吗?

顺便说一句,我想使用自己的凭据(谷歌服务帐户)而不是用户帐户,用 Google Play 服务实现它的方法是什么?

提前致谢

【问题讨论】:

    标签: android google-drive-api google-drive-android-api


    【解决方案1】:

    使用look here,它可以完成您提到的所有操作。不过,我不知道“简单”的要求。或者通过官方DEMO code here。但这绝对不是“双线”努力。

    【讨论】:

    • 非常感谢。我想问你关于使用此代码实现服务帐户,我在这里看到:hardcoded credentials 如何与其他库一起实现,它使用 GoogleCredential 进行身份验证,使用此密钥方法: .setServiceAccountId(G_SERVICE_EMAIL) .setServiceAccountPrivateKeyFromP12File (PKC_12_FILE) 不需要登录。但我不知道如何在您的代码中实现这一点,因为 GoogleApiClient 构建器没有 Google Service Account 方法。
    • 很遗憾,我对凭据一无所知。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-26
    • 2022-08-18
    相关资源
    最近更新 更多