我在使用Google Contacts API创建联系人条目时遇到问题 . 我正在使用PHP来做到这一点 . 我的问题是,我可以在用户联系人中创建一个条目,但没有设置名称 . 要设置的唯一字段是电子邮件地址 . 例如,这是我发送的XML:

<?xml version="1.0"?>
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005">
  <gd:name>
    <gd:givenName>John</gd:givenName>
    <gd:familyName>Smith</gd:familyName>
    <gd:fullName>John Smith</gd:fullName>
  </gd:name>
  <gd:email address="john@smith.com" rel="http://schemas.google.com/g/2005#home"/>
</atom:entry>

这是返回的内容:

<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:gContact="http://schemas.google.com/contact/2008" xmlns:gd="http://schemas.google.com/g/2005">
<id>http://www.google.com/m8/feeds/contacts/user@domain/base/xyz123</id>
<updated>2015-05-13T08:30:56.531Z</updated>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#contact"/>
<title type="text"/>
<link rel="http://schemas.google.com/contacts/2008/rel#edit-photo" type="image/*" href="https://www.google.com/m8/feeds/photos/media/user@domain/xyz123/abc987"/>
<link rel="self" type="application/atom+xml" href="https://www.google.com/m8/feeds/contacts/user@domain/xyz123"/>
<link rel="edit" type="application/atom+xml" href="https://www.google.com/m8/feeds/contacts/user@domain/xyz123/1431505856531001"/>
<gd:email rel="http://schemas.google.com/g/2005#home" address="john@smith.com"/>
</entry>

请注意,返回时“title”为空:

<title type="text"/>

我错过了什么?

编辑

总结一下 - 我可以创建一个联系人条目 . 我在XML I post中设置了givenName,familyName,fullName和email,如第一个代码块所示 . 已成功创建联系人,但仅保存电子邮件 . GivenName,FamilyName和FullName未设置 . 所需的行为是创建包含givenName,familyName,fullName和email的联系人 .

Solved

要设置 Headers ,您必须添加xml元素:

<atom:title>John Smith</atom:title>

我错误地假设设置givenName和familyName,而fullName将设置 Headers . 所以我原来的XML Request看起来像这样:

<?xml version="1.0"?>
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005">
  <atom:title>John Smith</atom:title>
  <gd:name>
    <gd:givenName>John</gd:givenName>
    <gd:familyName>Smith</gd:familyName>
    <gd:fullName>John Smith</gd:fullName>
  </gd:name>
  <gd:email address="john@smith.com" rel="http://schemas.google.com/g/2005#home"/>
</atom:entry>