Google Contact API v3 通过 JavaScript 不创建 Contact

Google Contact API v3 via JavaScript not creating Contact

本文关键字:Contact 创建 JavaScript v3 API Google 通过      更新时间:2023-09-26

我想知道你能不能帮忙,拜托。

我正在尝试通过JavaScript使用Google Contact API v3来创建联系人,使用以下默认的ATOM + XML字符串:

  var resource = '<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"/>  <gd:name>     <gd:givenName>Elizabeth</gd:givenName>     <gd:familyName>Bennet</gd:familyName>     <gd:fullName>Elizabeth Bennet</gd:fullName>  </gd:name>  <atom:content type="text">Notes</atom:content>  <gd:email rel="http://schemas.google.com/g/2005#work"    primary="true"    address="liz@gmail.com" displayName="E. Bennet"/>  <gd:email rel="http://schemas.google.com/g/2005#home"    address="liz@example.org"/>  <gd:phoneNumber rel="http://schemas.google.com/g/2005#work"    primary="true">    (206)555-1212  </gd:phoneNumber>  <gd:phoneNumber rel="http://schemas.google.com/g/2005#home">    (206)555-1213  </gd:phoneNumber>  <gd:im address="liz@gmail.com"    protocol="http://schemas.google.com/g/2005#GOOGLE_TALK"    primary="true"    rel="http://schemas.google.com/g/2005#home"/>  <gd:structuredPostalAddress      rel="http://schemas.google.com/g/2005#work"      primary="true">    <gd:city>Mountain View</gd:city>    <gd:street>1600 Amphitheatre Pkwy</gd:street>    <gd:region>CA</gd:region>    <gd:postcode>94043</gd:postcode>    <gd:country>United States</gd:country>    <gd:formattedAddress>      1600 Amphitheatre Pkwy Mountain View    </gd:formattedAddress>  </gd:structuredPostalAddress></atom:entry>';

以及以下请求:

 gapi.client.request({
      'path': '/m8/feeds/contacts/default/full',
      'headers': { 'Content-Type': 'application/atom+xml', 'GData-Version': 3.0 },
      'method': 'POST',
      'body': resource,
      'callback': writeResponse
    });

我得到的原始回复似乎在最后说它创建正常:

{"gapiRequest":{"data":{"body":"'n'n http://www.google.com/m8/feeds/contacts/martinkeywood%40gmail.com/base/2c9884718f97c163'n 2016-03-22T10:23:42.228Z'n 2016-03-22T10:23:42.228Z'n 'n 'n Notes'n 'n 'n 'n 'n Elizabeth Bennet'n Elizabeth'n Bennet'n 'n 'n 'n 'n  (206)555-1212 'n  (206)555-1213 'n 'n  1600 Amphitheatre Pkwy Mountain View 'n 1600 Amphitheatre Pkwy'n Mountain View'n CA'n 94043'n United States'n 'n'n","headers":{"ETag":"'"Q3w5cDVSLit7I2A9XRNbFkkIRQY.'"","Vary":"X-Origin","Content-Type":"application/atom+xml; charset=UTF-8","Date":"Tue, 22 Mar 2016 10:23:42 GMT","Expires":"Tue, 22 Mar 2016 10:23:42 GMT","Cache-Control":"private, max-age=0","Server":"GSE","Transfer-Encoding":"chunked"},"status":201,"statusText":"Created"}}}

但该联系人根本没有出现在我的谷歌通讯录中。

请问有什么想法吗??

要将联系人创建到"所有联系人"组中,您需要在联系人XML数据中分配"组成员信息"。

"<gContact:groupMembershipInfo deleted='"false'" href='"http://www.google.com/m8/feeds/groups/{USER EMAIL}/base/6'"/>"

即使您也可以使用Google联系人API版本3.0获取所有组ID。请参阅"使用联系人组"部分。获得所有组成员信息的列表后,您可以通过在上面的代码行中提供组ID来代替"6"来创建您的愿望组的联系人。