繁体   English   中英

从用户Google云端硬盘中选择任何文件,然后通过Android应用将其发送(上传)到我的服务器

[英]Pick any file from users Google Drive and send (Upload) it to my server via Android app

我正在使用Google Drive Android API(GDAA),并且希望使用户能够从其Drive中选择任何文件(Google文档,表格,图像,视频,音频等)并将其发送到应用服务器。

我已经在网上关注了一些教程以及有关使用GDAA的Google官方文档。

我也尝试了以下答案: 通过FileId获取Google云端硬盘文件的内容

但这也不起作用。 我总是将result.getStatus().isSuccess()设为false 我不理解为什么。

以下是我的open()函数:

private void open() {
    DriveFile driveFile = mFileId.asDriveFile();
    driveFile.open(mGoogleApiClient, DriveFile.MODE_READ_ONLY, null)
            .setResultCallback(driveContentsCallback);
    mFileId = null;
}

以下是我得到result.getStatus().isSuccess()false的回调:

/**
 * This is Result result handler of Drive contents.
 */
final ResultCallback<DriveApi.DriveContentsResult> driveContentsCallback =
        new ResultCallback<DriveApi.DriveContentsResult>() {
            @Override
            public void onResult(DriveApi.DriveContentsResult result) {

                if (!result.getStatus().isSuccess()) {
                    return;
                }

                // Read from the input stream an print to LOGCAT
                DriveContents driveContents = result.getDriveContents();
                BufferedReader reader = new BufferedReader(new InputStreamReader(driveContents.getInputStream()));
                StringBuilder builder = new StringBuilder();
                String line;
                try {
                    while ((line = reader.readLine()) != null) {
                        builder.append(line);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
                String contentsAsString = builder.toString();
                Log.i("ContentAsString", contentsAsString);

                // Close file contents
                driveContents.discard(mGoogleApiClient);
            }
        };

现在,我依靠此代码。 我已经能够打开Goog​​le表格和文档,但是我需要将它们以及图像和视频上传到我的应用服务器(无需打开文件)。 有没有办法可以做到这一点?

我已经阅读了有关Storage Access Framework(SAF)的信息,它可能允许我从以后访问Kitkat的Google云端硬盘文件,但是我的应用支持在JellyBean以及更高版本上运行的设备,因此我要使用GGDA。

我尚未检查REST API。 我想了解我是否以正确的方式进行操作,或者是否有完全不同的方式来实现自己想要的目标。 如果这是正确的方法,那么哪里出了问题?

任何帮助将不胜感激。

您可以尝试以下解决方法:

如果这些方法没有帮助,请尝试在Google Developer Console中基于新项目创建新的API密钥。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM