Добавьте контакт в группу, используя Zend_GData и API контактов Google - PullRequest
3 голосов
/ 26 мая 2011

У меня есть приложение, использующее zend_gdata, и создаю контакт с кодом ниже.

$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);

// add name element
$name = $doc->createElement('gd:name');
$entry->appendChild($name);

$fullName = $doc->createElement('gd:fullName', htmlentities($data->firstname . ' ' . $data->lastname));
$name->appendChild($fullName);

// insert entry
$entryResult = $gdata->insertEntry($doc->saveXML(), 'http://www.google.com/m8/feeds/contacts/default/full');

Есть ли возможность добавить функцию в только что созданный контакт?

Ответы [ 2 ]

2 голосов
/ 11 октября 2011

У меня большой класс, и я не могу все это вставить, вам нужно как-то собрать это вместе

шаг 1)

получить все группы (http://raiyaraj.wordpress.com/2008/09/17/gmail-gdata-contacts-group-via-proxy/) и найтиидентификатор вашей группы или создайте его (вы можете сделать это с помощью Zend Framework), если он не существует

шаг 2)

сгенерируйте xml

// create new entry
        $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');
        $entry->setAttributeNS('http://www.w3.org/2000/xmlns/' , 'xmlns:gContact', 'http://schemas.google.com/contact/2008');
        $doc->appendChild($entry);

...add various stuff....
    $name = $doc->createElement('gd:name');
            $entry->appendChild($name);
            $fullName = $doc->createElement('gd:fullName', $this->name);
            $name->appendChild($fullName);
.....

        $group = $doc->createElement('gContact:groupMembershipInfo');
        $group->setAttribute('deleted' ,'false');
        $group->setAttribute('href' ,'http://www.google.com/m8/feeds/groups/' .urlencode($this->email) . '/base/'.$this->group_id);
        $entry->appendChild($group);

шаг 3)

подключитесь к gmail и выполните запрос

$service = $this->service;
// perform login and set protocol version to 3.0
$client = $service;
$gdata = new Zend_Gdata($client);
$gdata->setMajorProtocolVersion(3);
$entryResult = $gdata->insertEntry($this->getXML(), 'https://www.google.com/m8/feeds/contacts/default/full');

return $entryResult->getLink('edit');

обратите внимание, что вы возвращаете ссылку для редактирования, чтобы при ее сохранении вы могли обновить контакт или проверить наличие изменений

0 голосов
/ 26 мая 2011

Да, это возможно. Обратитесь к следующей документации для того же.

http://code.google.com/apis/contacts/docs/3.0/reference.html#groupMembershipInfo

...