I've been tearing my hair out with the following all day:
I'm attempting to send manual requests to Google Goggles with PHP-ported code from this blog post: http://notanothercodeblog.blogspot.com/2011/02/google-goggles-api.html
The original blog post has apparantly working code written in .NET, but my platform is PHP. The code I have is:
$googleID = substr(md5(rand()), 0, 16);
/* */
$url = 'http://www.google.com/goggles/container_proto?cssid=' . $googleID;
// $开发者_如何学JAVAurl = '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);
I keep getting the following response back from Google:
"Unparseable Container Request"
I believe my issue is with the format of $googleCodes
. The original article has the following for it:
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 };
I realise this is an issue that is potentially very unique, but I'm hoping someone with experience with .NET byte arrays could point me in the right direction.
$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);
foreach ($googleCodes as $n=>$char) { $googleCodes[$n] = chr($char); }
I think these are codes for the characters, and I suspect they're being sent in binary. Either that, or they should be zero padded. Can you provide a link to the original method in the foreign language? We just want to emulate their method. I think your numbers are running together, so it's a question of the desired format.
精彩评论