2012-07-09 42 views
1

最近,我正在嘗試使用scribe-java(https://github.com/fernandezpablo85/scribe-java)將Google Drive集成到我的應用程序中。 和通過Id方法列出文件/獲取文件正常工作。但我無法插入新的File方法正常工作。 這裏是我的代碼(插入):如何使用scribe-java將新文件插入Google Drive

OAuthService service = new ServiceBuilder() 
       .provider(GoogleApi.class) 
       .apiKey("[my api key]") 
       .apiSecret("[my api secret]") 
       .scope(SCOPE) 
       .callback("[my callback]") 
       .build(); 
Token token = new Token(accessToken, accessSecret); 
OAuthRequest request = new OAuthRequest(Verb.POST, "https://www.googleapis.com/drive/v2/files"); 
service.signRequest(token, request); 
Response response = request.send(); 

這將在我的谷歌驅動器中的「無題」命名的文件,我的問題是如何從本地文件系統上傳我的文件,並指定一個名字嗎?因爲我嘗試添加添加主體參數,添加標題,他們都不工作。非常感謝

+0

文檔要求你做什麼?你應該以什麼格式發送文件內容到谷歌驅動器? – 2012-07-09 18:48:10

回答

1

您正在收到一個「無標題」的命名文件,因爲您沒有通過POST請求發送任何內容。 您可以從documentation中找到有關Google Drive API的媒體上傳協議的更多信息。

這是表示該多上傳方式協議爲例:

POST https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart 

Authorization: Bearer <Access token> 
Content-Length: 44332 
Content-Type: multipart/related; boundary="===============0124852474844509178==" 

===============0124852474844509178== 
Content-Type: application/json 

{'title': 'My Image'} 
===============0124852474844509178== 
Content-Type: image/png 

<Binary data removed> 
===============0124852474844509178== 

我不熟悉的抄寫員,但你可能想使用強類型類Google APIs client library for Java其抽象的所有協議交互嘗試。 Google Drive API的reference guide包含使用此客戶端庫的代碼片段。

相關問題