[英]Not able to add a contact into google in PHP curl
我想将带有数据的联系人添加到google contacts。我收到错误消息,因为“您的请求中有错误。仅此而已。”
代码如下
<?php
$contact_detail='<?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:firstName>John</gd:firstName>
<gd:additionalName> test</gd:additionalName>
<gd:givenName>Doe</gd:givenName>
</gd:name>
<gd:email address="john@doe.com" rel="http://schemas.google.com/g/2005#work"/>
<gd:email address="john2@doe.com" rel="http://schemas.google.com/g/2005#home"/>
<gd:organization rel="http://schemas.google.com/g/2005#work">
<gd:orgName>John Deere</gd:orgName>
<gd:orgTitle>Owner</gd:orgTitle>
</gd:organization>
</atom:entry>';
$url="https://www.google.com/m8/feeds/contacts/default/full";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$contact_detail");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
print($output);
curl_close($ch);
https://developers.google.com/google-apps/contacts/v2/developers_guide_protocol
要发布此条目,请按以下方式将其发送到联系人列表帖子的URL。 首先,使用application / atom + xml内容类型将Atom元素放置在新POST请求的正文中。 然后将其发送到帖子URL。 例如,要将联系人添加到属于liz@gmail.com的联系人列表中,请将新条目发布到以下URL: https : //www.google.com/m8/feeds/contacts/liz%40gmail.com/充分
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.