11

Google Appsでエントリを更新しようとすると、No ETag found返されます。エントリの追加は問題なく機能しますが、エントリを更新または削除することはできません!?

ETagは、コードの最後の行の1つでヘッダーに追加されます。

$this->gdata->updateEntry($doc->saveXML(), $update_entry->getEditLink()->href, null, array('If-Match' => '*'));

例外

Expected response code 200, got 409

コード

private function update_entry($data, $update_entry=null){
        $doc = new DOMDocument();
        $doc->formatOutput = true;

        $entry = $doc->createElement('atom:entry');
        $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:atom', 'http://www.w3.org/2005/Atom');
        $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gd', 'http://schemas.google.com/g/2005');
        $doc->appendChild($entry);

        if($update_entry){
            preg_match('/^"?([^"]*)"?$/i', $update_entry->getEtag(), $matches);
            $etag_value = $matches[1];

            $entry->setAttribute('gd:etag', $etag_value);
            $id = $doc->createElement('id', 'http://www.google.com/m8/feeds/contacts/'.$this->admin_user.'/base/'.$data['alias']);
        $entry->appendChild($id);
        }

        $name = $doc->createElement('gd:name');
        $entry->appendChild($name);
        $fullName = $doc->createElement('gd:fullName', $data['name']);
        $name->appendChild($fullName);

        if($data['title']){
            $org = $doc->createElement('gd:organization');
            $org->setAttribute('rel' ,'http://schemas.google.com/g/2005#work');
            $entry->appendChild($org);
            $orgName = $doc->createElement('gd:orgTitle', $data['title']);
            $org->appendChild($orgName);
        }

        if($data['email']){
            $email = $doc->createElement('gd:email');
            $email->setAttribute('address', $data['email']);
            $email->setAttribute('rel', 'http://schemas.google.com/g/2005#work');
            $entry->appendChild($email);
        }

        if($data['phone_work']){
            $phone_work = $doc->createElement('gd:phoneNumber', $data['phone_work']);
            $phone_work->setAttribute('rel', 'http://schemas.google.com/g/2005#work');
            $entry->appendChild($phone_work);
        }

        if($data['phone_work_mobile']){
            $phone_work_mobile = $doc->createElement('gd:phoneNumber', $data['phone_work_mobile']);
            $phone_work_mobile->setAttribute('rel', 'http://schemas.google.com/g/2005#work_mobile');
            $entry->appendChild($phone_work_mobile);
        }

        if($update_entry){
            echo $doc->saveXML();
            $this->gdata->updateEntry($doc->saveXML(), $update_entry->getEditLink()->href, null, array('If-Match' => $etag_value));
        }
        else{
            $this->gdata->insertEntry($doc->saveXML(), 'http://www.google.com/m8/feeds/contacts/'.self::DOMAIN.'/full');
        }
    }

XML

<?xml version="1.0"?>
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" gd:etag="CxFbERtcFit7I2Bu">
  <id>http://www.google.com/m8/feeds/contacts/admin_user@domain.com/base/alias</id>
  <gd:name>
    <gd:fullName>name</gd:fullName>
  </gd:name>
  <gd:organization rel="http://schemas.google.com/g/2005#work">
    <gd:orgTitle>title</gd:orgTitle>
  </gd:organization>
  <gd:email address="mail@domain.com" rel="http://schemas.google.com/g/2005#work"/>
  <gd:phoneNumber rel="http://schemas.google.com/g/2005#work">22260435</gd:phoneNumber>
  <gd:phoneNumber rel="http://schemas.google.com/g/2005#work_mobile">1112223</gd:phoneNumber>
</atom:entry>
4

2 に答える 2

5

一見、すべてが問題ないように見えますが、グーグルのドキュメント(しゃれを意図したもの)を見ると、グーグルはエントリタグの属性としてetagを直接配置しているようです:

<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" gd:etag="BxAaTxRZAyp7ImBq">

編集:ドキュメントはもちろんGooglin'で見つけることができますが、直接リンクの方が簡単かもしれません。

于 2012-08-25T11:32:03.720 に答える
3

Eタグ付きのヘッダーを追加する必要があります。気にしない場合は、次を使用できます。

$this->gdata->setHeaders('If-Match: *');
于 2012-08-15T15:03:37.433 に答える