问题来更改与谷歌联系人API的联系人

时间:2019-05-27 16:43:58

标签: php google-contacts php-curl

我正在尝试通过PHP更改Google联系人,但是对于每个请求,Google服务器都不会回答我。如果我尝试以NULL发布google服务器,则会得到无效的XML,因此我认为PUT请求正确。 有人可以帮我举一些例子吗? 这是PHP中的代码

$access = 'xxx';
$user_email = urlencode('xxx@xxx');
$id_contatto = 'xxx';

$contactXML = '
    <entry gd:etag="*">
    <id>http://www.google.com/m8/feeds/contacts/'.$user_email.'/base/'.$id_contatto.'</id>
    <updated>2019-05-27T17:07:02.303Z</updated>
    <atom:category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#contact"/>
    <gd:name>
        <gd:givenName>Test</gd:givenName>
        <gd:familyName>Test</gd:familyName>
        <gd:fullName>Test Test</gd:fullName>
    </gd:name>
    <content type="text">Notes</content>
    <link rel="http://schemas.google.com/contacts/2008/rel#photo" type="image/*" href="https://www.google.com/m8/feeds/photos/media/'.$user_email.'/'.$id_contatto.'"/>
    <link rel="self" type="application/atom+xml" href="https://www.google.com/m8/feeds/contacts/'.$user_email.'/full/'.$id_contatto.'"/>
    <link rel="edit" type="application/atom+xml" href="https://www.google.com/m8/feeds/contacts/'.$user_email.'/full/'.$id_contatto.'"/>
    <gd:phoneNumber rel="http://schemas.google.com/g/2005#other" primary="true">456-123-2133</gd:phoneNumber>
    <gd:extendedProperty name="pet" value="hamster"/>
    <gd:groupMembershipInfo deleted="false" href="http://www.google.com/m8/feeds/groups/'.$user_email.'/base/6"/>
    </entry>
    </pre>';

$headers = array(
'If-Match: *',
'Gdata-version: 3.0',
'Content-type: application/atom+xml',
);

$contactQuery = 'https://www.google.com/m8/feeds/contacts/default/full/'.$id_contatto.'?access_token='.$access;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $contactQuery );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $contactXML);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
$result = curl_exec($ch);
if(curl_errno($ch)){
    $result = curl_error($ch);
}

var_dump($result);

这是超时后var_dump的结果:

string(0)“”

0 个答案:

没有答案