![](/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.