0
我一直在使用Googgle的自定義搜索引擎API以編程方式添加和刪除註釋。我覺得我非常密切地關注他們的文檔和其他技巧。我似乎無法避免「錯誤的請求」HTTP 400錯誤。我的代碼是低於Google CSE PHP CURL實現以編程方式添加/刪除註釋
$url = "http://www.google.com/cse/api/default/annotations/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array(
"Authorization: GoogleLogin auth='DQAAAMI......n9dGUyA'",
"Content-Type: text/xml"
));
curl_setopt($ch, CURLOPT_POST, 1);
$data = '<?xml version="1.0"?>'.chr(10);
$data .= '<Batch>'.chr(10);
$data .= chr(9).'<Add>'.chr(10);
$data .= chr(9). chr(9).'<Annotations>'.chr(10);
$data .= chr(9). chr(9). chr(9).'<Annotation about=\"\">'.chr(10);
$data .= chr(9).chr(9). chr(9). chr(9).'<Label name=\"my_engine\"/>'.chr(10);
$data .= chr(9). chr(9). chr(9).'</Annotation>'.chr(10);
$data .= chr(9). chr(9).'</Annotations>'.chr(10);
$data .= chr(9).'</Add>'.chr(10);
$data .= '</Batch>'.chr(10);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$ result = curl_exec($ ch);
if (curl_errno($ch)) {
$result = 'cURL ERROR -> ' . curl_errno($ch) . ': ' . curl_error($ch);
} else {
$returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo $returnCode."<br/>";
switch($returnCode){
case 200:
break;
default:
$result = 'HTTP ERROR -> ' . $returnCode;
break;
}
}
curl_close($ch);
echo $result;
如果有人能幫助我,或者至少引導我在正確的方向,我將非常感激