Google api php client Google API PHP客户端未使用V3 API保存联系人地址

Google api php client Google API PHP客户端未使用V3 API保存联系人地址,google-api-php-client,google-contacts-api,Google Api Php Client,Google Contacts Api,我正在使用GoogleAPI PHP客户端与Contacts API进行交互,我可以获得标题、电子邮件地址和电话号码来保存。但是,我无法获取要保存的联系人地址。我将请求中发送的内容与此处的文档进行了比较:所有内容似乎都是一样的 以下是调用API的代码: $doc = new \DOMDocument(); $doc->formatOutput = true; $entry = $doc->createElement('atom:entry'); $entry->setAttri

我正在使用GoogleAPI PHP客户端与Contacts API进行交互,我可以获得标题、电子邮件地址和电话号码来保存。但是,我无法获取要保存的联系人地址。我将请求中发送的内容与此处的文档进行了比较:所有内容似乎都是一样的

以下是调用API的代码:

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

$category = $doc->createElement('atom:category');
$category->setAttribute('scheme', 'http://schemas.google.com/g/2005#kind');
$category->setAttribute('term', 'http://schemas.google.com/contact/2008#contact');
$entry->appendChild($category);

$title = $doc->createElement('title', $name);
$entry->appendChild($title);

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

$contact = $doc->createElement('gd:phoneNumber', $workPhone);
$contact->setAttribute('rel', 'http://schemas.google.com/g/2005#work');
$entry->appendChild($contact);

$workAddress = $doc->createElement('gd:structuredPostalAddress');
$workAddress->setAttribute('rel', 'http://schemas.google.com/g/2005#work');
$entry->appendChild($workAddress);
$workStreet = $doc->createElement('gd:street', $workAddress1);
$workAddress->appendChild($workStreet);
$workPo = $doc->createElement('gd:pobox', $workAddress2);
$workAddress->appendChild($workPo);
$workXmlCity = $doc->createElement('gd:city', $workCity);
$workAddress->appendChild($workXmlCity);
$workXmlState = $doc->createElement('gd:region', $workState);
$workAddress->appendChild($workXmlState);
$workXmlZip = $doc->createElement('gd:postcode', $workZip);
$workAddress->appendChild($workXmlZip);
$wFormatted = $workAddress1 . $workCity;
$workFormatted = $doc->createElement('gd:formattedAddress', $wFormatted);
$workAddress->appendChild($workFormatted);

$xmlToSend = $doc->saveXML();
echo '<p>Making call</p>';

$client = GoogleHelper::getClient();

$req = new \Google_Http_Request('https://www.google.com/m8/feeds/contacts/default/full');
$req->setRequestHeaders(
    array('content-type' => 'application/atom+xml; charset=UTF-8; type=feed'));
          //,'GData-Version' => '3.0'));
$req->setRequestMethod('POST');
$req->setPostBody($xmlToSend);

$val = $client->getAuth()->authenticatedRequest($req);
$response = $val->getResponseBody();
$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);
$category=$doc->createElement('atom:category');
$category->setAttribute('scheme','http://schemas.google.com/g/2005#kind');
$category->setAttribute('term','http://schemas.google.com/contact/2008#contact');
$entry->appendChild($category);
$title=$doc->createElement('title',$name);
$entry->appendChild($title);
$email=$doc->createElement('gd:email');
$email->setAttribute('rel','http://schemas.google.com/g/2005#work');
$email->setAttribute('address',$workEmail);
$entry->appendChild($email);
$contact=$doc->createElement('gd:phoneNumber',$workPhone);
$contact->setAttribute('rel','http://schemas.google.com/g/2005#work');
$entry->appendChild($contact);
$workAddress=$doc->createElement('gd:structuredPostalAddress');
$workAddress->setAttribute('rel','http://schemas.google.com/g/2005#work');
$entry->appendChild($workAddress);
$workStreet=$doc->createElement('gd:street',$workAddress1);
$workAddress->appendChild($workStreet);
$workPo=$doc->createElement('gd:pobox',$workAddress2);
$workAddress->appendChild($workPo);
$workXmlCity=$doc->createElement('gd:city',$workCity);
$workAddress->appendChild($workXmlCity);
$workXmlState=$doc->createElement('gd:region',$workState);
$workAddress->appendChild($workXmlState);
$workXmlZip=$doc->createElement('gd:postcode',$workZip);
$workAddress->appendChild($workXmlZip);
$wFormatted=$workAddress1$工作城市;
$workFormatted=$doc->createElement('gd:formattedAddress',$wFormatted);
$workAddress->appendChild($workFormatted);
$xmlToSend=$doc->saveXML();
回音“打电话”

; $client=GoogleHelper::getClient(); $req=new\Google\u Http\u请求('https://www.google.com/m8/feeds/contacts/default/full'); $req->setRequestHeaders( 数组('content-type'=>'application/atom+xml;charset=UTF-8;type=feed'); //,'GData-Version'=>'3.0'); $req->setRequestMethod('POST'); $req->setPostBody($xmlToSend); $val=$client->getAuth()->authenticatedRequest($req); $response=$val->getResponseBody();
正如您将在上面看到的,我已经注释掉了我试图添加GData版本头的地方,因为这样做没有保存任何内容

以下是请求主体的外观:

<?xml version="1.0"?>
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005">
  <atom:category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#contact"/>
  <title>address test</title>
  <gd:email rel="http://schemas.google.com/g/2005#work" address="work@working.com"/>
  <gd:phoneNumber rel="http://schemas.google.com/g/2005#work">123-123-1234</gd:phoneNumber>
  <gd:structuredPostalAddress rel="http://schemas.google.com/g/2005#work">
    <gd:street>123 Fake St</gd:street>
    <gd:pobox>333</gd:pobox>
    <gd:city>Minneapolis</gd:city>
    <gd:region>MN</gd:region>
    <gd:postcode>55427</gd:postcode>
    <gd:formattedAddress>123 Fake StMinneapolis</gd:formattedAddress>
  </gd:structuredPostalAddress>
</atom:entry>

地址测试
123-123-1234
123号假街
333
明尼阿波利斯
锰
55427
圣明尼阿波利斯123号

我尝试了上面发布的代码,我能够创建一个联系人,联系人地址也被保存。当您指定G-data版本时,地址是否已保存?当我指定G-data版本时,不会创建联系人