Google联系人api返回无效的XML文档错误,并且未保存到我的联系人

时间:2018-12-13 05:15:11

标签: ruby xml ruby-on-rails-4 google-contacts googlecontactsapi

我正在使用HTTP POST创建新联系人,但是这些联系人已保存在“其他联系人”中。

请求正文:

<?xml version="1.0" encoding="UTF-8"?>
<entry>
  <category scheme="https://schemas.google.com/g/2005#kind" term="https://schemas.google.com/contact/2008#contact" />
  <title>test Sun 6:00pm Ashwin P</title>
  <gd:name>
      <gd:fullName>test Sun 6:00pm Ashwin P</gd:fullName>
  </gd:name>
  <gd:phoneNumber label="Father">+6589822222</gd:phoneNumber>
  <gContact:groupMembershipInfo deleted="false" href="https://www.google.com/m8/feeds/groups/demo@gmail.com/base/6" />
</entry>

另一个请求正文:

<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>test Sun  6:00pm Ashwin P</gd:givenName>
    <gd:familyName>test Sun  6:00pm Ashwin P</gd:familyName>
    <gd:fullName>test Sun  6:00pm Ashwin P</gd:fullName>
  </gd:name>
  <atom:content type="text">Notes</atom:content>
  <gd:email rel="http://schemas.google.com/g/2005#work" primary="true" address="demo@gmail.com" displayName="test Sun  6:00pm Ashwin P"/> 
  <gd:email rel="http://schemas.google.com/g/2005#home" address="demo@gmail.com"/>
  <gd:phoneNumber rel="http://schemas.google.com/g/2005#home" primary="true">+6589822222</gd:phoneNumber> 
  <gContact:groupMembershipInfo deleted="false" href="https://www.google.com/m8/feeds/groups/paresh.tps@gmail.com/base/6"/>
</atom:entry>

我发现在“我的联系人”中插入联系人的唯一解决方案是将该标签添加到XML请求:

<gContact:groupMembershipInfo href='http://www.google.com/m8/feeds/groups/demo@gmail.com/base/6'/>

错误:

REXML::ParseException
The document "<?xml version='1.0'?>\n" does not have a valid root

响应错误

response.read_body
"Invalid XML Document."

谢谢

1 个答案:

答案 0 :(得分:0)

只需添加名称空间,看起来就很好

在这里,需要更换

<entry>

<entry xmlns:gd = "http://www.w3.org/TR/html4/" xmlns:gContact = "http://www.w3.org/TR/html4/">