2013-05-13 58 views
1

以下代码导致400错误请求...您能看到任何明显的问题吗?Google Fusion Table - 使用PHP API的Google API客户端创建新表格

$column = new Google_Column(); 
$column->setName('foo'); 
$column->setType('TEXT'); 

$table = new Google_Table(); 
$table->setName('bar'); 
$table->setColumns(array($column)); 

// $client below is a successfully authenticated Google_Client instance 
$service = new Google_FusiontablesService($client); 
$result = $service->table->insert($table); // 400 Bad Request exception thrown 

Google_Client通过“服务帐户”进行身份验证,我可以运行其他请求,例如, $service->query->sql()成功。

Google API客户端版本为0.6.2(最新)。

谢谢。

更新:请求对象转储:

Google_HttpRequest Object 
(
    [batchHeaders:Google_HttpRequest:private] => Array 
     (
      [Content-Type] => application/http 
      [Content-Transfer-Encoding] => binary 
      [MIME-Version] => 1.0 
      [Content-Length] => 
     ) 

    [url:protected] => https://www.googleapis.com/fusiontables/v1/tables 
    [requestMethod:protected] => POST 
    [requestHeaders:protected] => Array 
     (
      [content-type] => application/json; charset=UTF-8 
      [content-length] => 162 
      [authorization] => Bearer someHashHere 
     ) 

    [postBody:protected] => {"columns":[{"name":"Project","type":"TEXT"}],"description":"Created on 2013-05-14 10:41:44","isExportable":"true","name":"foobar"} 
    [userAgent:protected] => My app name google-api-php-client/0.6.0 
    [responseHttpCode:protected] => 
    [responseHeaders:protected] => 
    [responseBody:protected] => 
    [accessKey] => 
) 

回答

2

它看起来很简单,“TEXT”不是有效的列类型。您需要使用“STRING”。

0

的isExportable位也是必需的参数创建一个表(https://developers.google.com/fusiontables/docs/v1/reference/table/insert)时。当你设置的时候会发生什么?

+0

不,它可能是必需的,但它对这个错误没有任何影响:(我有一个来自Fusion Tables新闻组的示例:https://code.google.com/p/google-api -php-client/issues/detail?id = 192#c4稍后会调查并更新,如果有帮助的话 – Yuriy 2013-05-14 06:52:29

+0

我之前发布的链接无关紧要,用请求转储更新了我的帖子。 – Yuriy 2013-05-14 09:45:57