我想知道你是否可以提供帮助。
我正在尝试通过JavaScript使用Google Contact API v3创建一个Contact,其中包含以下默认的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"}}}
但该联系人根本没有出现在我的Google通讯录中。
任何想法,请?
答案 0 :(得分:0)
用于创建联系人&#34;所有联系人&#34;你需要分配&#34; groupMembershipInfo&#34;在您的联系人XML数据中。
"<gContact:groupMembershipInfo deleted=\"false\" href=\"http://www.google.com/m8/feeds/groups/{USER EMAIL}/base/6\"/>"
即使您也可以使用Google Contacts API Version 3.0获取所有群组ID。请参阅&#34;使用联系人组&#34;部分。获取所有groupMembershipInfo的列表后,您可以通过在&#34; 6&#34;的位置提供groupId到上述代码行来创建与您的愿望组的联系。