我已经得到了几乎完整的API工作,与创建和删除文档和文件夹。但我无法更新文档。使用gdata时非常简单,但由于此代码必须适用于所有Android设备,因此我必须使用google api java客户端。这里是我测试更新的方法:更新谷歌文档与谷歌API api客户端
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;
}
}
什么情况是,我只需要创建一个新的文件(与给定的内容,创建一个新的文件运行完美)。如果我添加“如果 - 匹配:*” - 头,我得到这个异常:
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)
...
你只是让我约8%更开心,谢谢! – pgsandstrom 2010-11-19 14:07:05
哦,我的目标是10%。 Bummer;) – 2010-11-19 14:18:45
你让我快乐3%,所以我猜你现在已经超出了你的目标。 ;) – 2011-06-02 11:47:15