Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用Google Contacts API 3创建联系人_Php_Xml_Google Api Php Client_Google Contacts Api - Fatal编程技术网

Php 使用Google Contacts API 3创建联系人

Php 使用Google Contacts API 3创建联系人,php,xml,google-api-php-client,google-contacts-api,Php,Xml,Google Api Php Client,Google Contacts Api,我在使用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"> <g

我在使用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 type="text"/>

http://www.google.com/m8/feeds/contacts/user@域/基/xyz123
2015-05-13T08:30:56.531Z
请注意,“标题”在返回时为空:

<?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 type="text"/>

我错过了什么

编辑

总而言之,我可以创建一个联系人条目。我在我发布的XML中设置了givenName、familyName、fullName和email,如第一个代码块所示。联系人已成功创建,但仅保存电子邮件。未设置GivenName、FamilyName和FullName。理想的行为是创建一个包含givenName、familyName、fullName和电子邮件的联系人

已解决

要设置标题,必须添加xml元素:

<atom:title>John Smith</atom:title>
约翰·史密斯 我错误地认为设置givenName、familyName和fullName会设置标题。因此,我最初的XML请求如下所示:

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

约翰·史密斯
约翰
史密斯
约翰·史密斯

寻求调试帮助的问题(“为什么此代码不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现这些问题所需的最短代码。请将您的解决方案作为答案发布。