0
新しいドキュメントを作成し、そのドキュメントにコンテンツを更新しようとしています。最後の2日間は、ドキュメントのタイトルを更新することに成功しましたが、コンテンツは更新されませんでした。このエラーが発生しました:GoogleドキュメントリストAPI - 新しいドキュメントを作成してコンテンツを更新する
com.google.gdata.util.PreconditionFailedException: Mismatch: etags = ["GEIJRhlABSt7ImBr"], version = [gqdjfe36]
<errors xmlns='http://schemas.google.com/g/2005'><error><domain>GData</domain><code>etagsMismatch</code><internalReason>Mismatch: etags = ["GEIJRhlABSt7ImBr"], version = [gqdjfe36]</internalReason></error></errors>
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:606)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
at com.google.gdata.client.Service.update(Service.java:1563)
at com.google.gdata.client.Service.update(Service.java:1530)
at com.google.gdata.client.GoogleService.update(GoogleService.java:583)
at com.google.gdata.client.media.MediaService.update(MediaService.java:484)
at com.google.gdata.data.BaseEntry.update(BaseEntry.java:639)
at GoogleDocuments.main(GoogleDocuments.java:51)
Exception in thread "main" java.lang.NullPointerException
at GoogleDocuments.main(GoogleDocuments.java:60)
今日の朝、私は同じコードを試して、ドキュメントのタイトルと内容の更新に成功しました。これは本当に予測できません。 私は何時間も費やしましたが、何が間違っているのかまだ分かりません。
は私にデビッド
Javaコードを助けてくれてありがとう:
import java.io.IOException;
import java.net.URL;
import com.google.gdata.client.docs.DocsService;
import com.google.gdata.data.docs.DocumentListEntry;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;
import com.google.gdata.data.PlainTextConstruct;
import com.google.gdata.data.docs.*;
import com.google.gdata.data.media.MediaByteArraySource;
public class GoogleDocuments {
/**
* @param args
*/
public static void main(String[] args) {
DocsService client = new DocsService("uop-test-v1");
try {
client.setUserCredentials("[email protected]", "mypassword");
} catch (AuthenticationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DocumentListEntry createdEntry = null;
// Create an empty word processor document
try {
createdEntry = createNewDocument("NewDocTitle", client);
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (ServiceException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
System.out.println("Document now online @ :" + createdEntry.getHtmlLink().getHref());
System.out.println("Title of the document :" + createdEntry.getTitle().getPlainText());
createdEntry.setTitle(new PlainTextConstruct("NewTitle"));
DocumentListEntry updatedEntry = null;
try {
updatedEntry = createdEntry.update();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("New title of the document :" +updatedEntry.getTitle().getPlainText());
updatedEntry.setMediaSource(new MediaByteArraySource("updated content".getBytes(), "text/plain"));
try {
updatedEntry.updateMedia(true);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Document updated!");
}
static public DocumentListEntry createNewDocument(String title, DocsService client) throws IOException, ServiceException {
DocumentListEntry newEntry = null;
newEntry = new DocumentEntry();
newEntry.setTitle(new PlainTextConstruct(title));
return client.insert(new URL("http://docs.google.com/feeds/default/private/full"), newEntry);
}
}
を見てください、私はこのエラーを得ました。ドキュメント上の操作の間に新しいコピーが必要なようです。 – bsautner
@bsautner、これを行う方法の例がありますか? –
申し訳ありません - 私はそれを安定に保つことができなかったので、私のアプリケーションの出力としてgdocsを使用することを断念しました。メモリが役立つ場合 - ファイル名の設定やセルの編集など、ドキュメントを編集するコードがある場合は、各操作を別々に実行する必要があります。ファイルを開き、タイトルを設定して閉じます。再オープンして細胞を挿入して閉じてください。 – bsautner