How to create a new contact via Google Contacts API?

喜欢而已 提交于 2019-12-24 06:58:13

问题


I am creating a new contact as described in Google Contacts API . Specifically, I do a POST to https://www.google.com/m8/feeds/contacts/default/full. The content that I POST is taken directly from Google Contacts API document and also copied below.

The problem is Google puts the newly created contact under "Other Contacts". That is if I open https://contacts.google.com/ in the browser, the new contact is not shown. I have to go to the sidebar in the left, click "More" and then click "Other Contacts".

How can I create a contact programmatically, so that I can see it directly in https://contacts.google.com/ without going to "Other Contacts"?

<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>

回答1:


First, I recommend making sure that you sent an authorized request with the header GData-Version: 3.0 included.

https://www.google.com/m8/feeds/groups/default/full

A successful request will return a list of groups, 'My Contacts' included.

Using the groupId of 'My Contacts', you can now change the Group Membership of that contact.

Check this google forum for more info.



来源:https://stackoverflow.com/questions/44396248/how-to-create-a-new-contact-via-google-contacts-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!