![](/img/trans.png)
[英]How to upload and download using Google Drive API in Android?
[英]How to upload/download files using android on google drive?
我正在使用Google Drive Rest API在android上执行上载/下载操作,但是在google doc上没有可恢复操作的明确API文档。 我已经成功获取驱动器操作的访问令牌。 即使我不能添加google drive rest API标签。 任何帮助,将不胜感激。
我已经成功获取驱动器操作的访问令牌。 任何帮助,将不胜感激。
try {
URL url;
url = new URL("https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable");
HttpURLConnection request;
request = (HttpURLConnection) url.openConnection();
request.setRequestMethod("POST");
request.setDoInput(true);
request.setDoOutput(true);
request.setRequestProperty("Authorization", "Bearer " + credential.getToken());
request.setRequestProperty("X-Upload-Content-Type", getMimeType(file.getPath()));
request.setRequestProperty("X-Upload-Content-Length", String.format(Locale.ENGLISH, "%d", file.length()));
request.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
String body = "{\"name\": \"" + file.getName() + "\", \"parents\": [\"" + "parentId12345678" + "\"]}";
request.setRequestProperty("Content-Length", String.format(Locale.ENGLISH, "%d", body.getBytes().length));
OutputStream outputStream ;
outputStream = request.getOutputStream();
outputStream.write(body.getBytes());
outputStream.close();
request.connect();
} catch (Exception e) {
e.printStackTrace();
}
https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable
会做的工作
从文档:
以下示例显示了如何启动一个可恢复会话来
POST https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable HTTP/1.1
Authorization: Bearer [YOUR_AUTH_TOKEN]
Content-Length: 38
Content-Type: application/json; charset=UTF-8
X-Upload-Content-Type: image/jpeg
X-Upload-Content-Length: 2000000
{
"name": "myObject"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.