PHP中的Google Goggles API解决方法问题

时间:2011-07-15 20:52:45

标签: php .net arrays google-goggles

我一整天都在扯掉头发:

我正在尝试使用此博客文章中的PHP移植代码向Google Goggles发送手动请求: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);

我不断收到Google的回复:

"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字节数组经验的人能指出我正确的方向。

1 个答案:

答案 0 :(得分:1)

$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); }

我认为这些是角色的代码,我怀疑它们是以二进制形式发送的。要么是,要么他们应该填零。你能用外语提供原始方法的链接吗?我们只想模仿他们的方法。我认为你的号码在一起运行,所以这是一个所需格式的问题。