我正在使用此脚本尝试从GMAIL中删除联系人,但无法删除。
我推荐:https://developers.google.com/glass/v1/reference/contacts/delete
我的剧本:
$id = '******';
$contact_mail = '********';
$contact_id = '************';
$contactXML = '<?xml version="1.0" encoding="utf-8"?>
<entry gd:etag="*">
<id>http://www.google.com/m8/feeds/contacts/'.$contact_mail.'/base/'.$contact_id.'</id>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#contact"/>
<link rel="self" type="application/atom+xml" href="https://www.google.com/m8/feeds/contacts/'.$contact_mail.'/full/'.$contact_id.'"/>
<link rel="edit" type="application/atom+xml" href="https://www.google.com/m8/feeds/contacts/'.$contact_mail.'/full/'.$contact_id.'"/></entry>';
$headers = array(
'Host: www.google.com',
'Gdata-version: 3.0',
'Content-length: '.strlen($contactXML),
'Content-type: application/atom+xml',
'Authorization: OAuth '.$access_token
);
$contactQuery = 'https://www.google.com/m8/feeds/contacts/default/full/'.$contact_id.'';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $contactQuery );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
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);
print_r($result);
请找出我错的地方或指导我任何其他解决方案。
答案 0 :(得分:1)
Authorization: OAuth ...
更改为Authorization: Bearer ...
还有其他一些问题可能是错误的(尤其是如何获取OAuth令牌),但如果没有从服务器收到的实际错误消息,则无法明确诊断。