1
API的解決方法問題,我一直在撕裂我的頭髮,用下面的所有天:谷歌護目鏡在PHP
我試圖手動請求從這個博客帖子發送至谷歌護目鏡用PHP-移植的代碼:http://notanothercodeblog.blogspot.com/2011/02/google-goggles-api.html
最初的博客文章使用.NET編寫的表觀工作代碼,但我的平臺是PHP。我的代碼是:
$googleID = substr(md5(rand()), 0, 16);
/* */
$url = 'http://www.google.com/goggles/container_proto?cssid=' . $googleID;
// $url = 'http://www.google.com/goggles/container_proto?cssid=';
// $googleCodes = array(0x22,0x00,0x62,0x3C,0x0A,0x13,0x22,0x02,0x65,0x6E,0xBA,0xD3,0xF0,0x3B,0x0A,0x08,0x01,0x10,0x01,0x28,0x01,0x30,0x00,0x38,0x01,0x12,0x1D,0x0A,0x09,0x69,0x50,0x68,0x6F,0x6E,0x65,0x20,0x4F,0x53,0x12,0x03,0x34,0x2E,0x31,0x1A,0x00,0x22,0x09,0x69,0x50,0x68,0x6F,0x6E,0x65,0x33,0x47,0x53,0x1A,0x02,0x08,0x02,0x22,0x02,0x08,0x01);
$googleCodes = array(34,0,98,60,10,19,34,2,101,110,186,211,240,59,10,8,1,16,1,40,1,48,0,56,1,18,29,10,9,105,80,104,111,110,101,32,79,83,18,3,52,46,49,26,0,34,9,105,80,104,111,110,101,51,71,83,26,2,8,2,34,2,8,1);
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, array("CssidPostBody" => implode("",$googleCodes)));
curl_setopt($handle, CURLOPT_HTTPHEADER, array("Content-Type: application/x-protobuffer",
"Pragma: no-cache"));
$response = curl_exec($handle);
/* */
print_r($response);
我一直從谷歌獲得以下響應回:
"Unparseable Container Request"
我相信我的問題是與$googleCodes
格式。原來的文章爲它下面:
private static byte[] CssidPostBody = new byte[] { 34, 0, 98, 60, 10, 19, 34,
2, 101, 110, 186, 211, 240, 59, 10, 8, 1, 16, 1, 40, 1, 48, 0, 56, 1, 18,
29, 10, 9, 105, 80, 104, 111, 110, 101, 32, 79, 83, 18, 3, 52, 46, 49,
26, 0, 34, 9, 105, 80, 104, 111, 110, 101, 51, 71, 83, 26, 2, 8, 2, 34,
2, 8, 1 };
我意識到這是潛在的非常獨特的一個問題,但我希望有人與.NET字節數組經驗可以點我在正確的方向。
感謝您的回覆。原始代碼位於:http://notanothercodeblog.blogspot.com/2011/02/google-goggles-api.html – Aaron