我已经获得了几乎完整的 API 来创建和删除文档和文件夹。但我无法更新文件。使用 gdata 非常简单,但由于此代码必须在所有 android 设备上运行,我必须使用 google api java 客户端。这是我测试更新的方法:
public void updateTest() throws IOException {
InputStreamContent isContent = new InputStreamContent();
isContent.inputStream = new ByteArrayInputStream("NEW CONTENT".getBytes("UTF-8"));
isContent.type = "text/plain";
HttpRequest request = transport.buildPostRequest();
request.setUrl("https://docs.google.com/feeds/default/media/document:0A[snip]3Y");
request.content = isContent;
// request.headers.set("If-Match", "*");
try {
request.execute().parseAs(DocumentListEntry.class);
} catch (HttpResponseException e) {
if (Constant.DEBUG) Log.d(TAG, "error: " + e.response.parseAsString());
throw e;
} catch (ClientProtocolException e) {
if (Constant.DEBUG) Log.d(TAG, "error: " + e.getMessage());
throw e;
}
}
发生的情况是我只是创建了一个新文档(使用给定的内容,创建一个新文档非常完美)。如果我添加了“If-Match: *”-header,我会得到这个异常:
11-19 11:17:16.536: DEBUG/DocsAPI(32195): error: <errors xmlns='http://schemas.google.com/g/2005'>
11-19 11:17:16.536: DEBUG/DocsAPI(32195): <error>
11-19 11:17:16.536: DEBUG/DocsAPI(32195): <domain>GData</domain>
11-19 11:17:16.536: DEBUG/DocsAPI(32195): <code>noPostConcurrency</code>
11-19 11:17:16.536: DEBUG/DocsAPI(32195): <internalReason>POST method does not support concurrency</internalReason>
11-19 11:17:16.536: DEBUG/DocsAPI(32195): </error>
11-19 11:17:16.536: DEBUG/DocsAPI(32195): </errors>
11-19 11:17:16.536: WARN/System.err(32195): com.google.api.client.http.HttpResponseException: 501 Not Implemented
11-19 11:17:16.540: WARN/System.err(32195): at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:209)
...