0

新しいドキュメントを作成し、コンテンツを更新しようとしています。この 2 日間、ドキュメントのタイトルの更新に成功することはありましたが、コンテンツの更新には成功しませんでした。このエラーが発生しました:

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("myemail...@gmail.com", "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);
  }
}
4

1 に答える 1

1

Google ドキュメントは、etags を使用してファイルのバージョン情報を追跡します。このエラーが発生した場合、ファイルの内容/メタコンテンツが変更されたことを意味します。考えられる修正の 1 つは、リソースを再度取得することです。

http://www.google.com/support/forum/p/apps-apis/thread?tid=2f5f76354541137b&hl=enをご覧ください。

于 2011-09-18T09:04:58.863 に答える