使用Google API PHP客户端1.0融合表插入方法在创建表上出现错误500

时间:2014-06-12 02:22:21

标签: php google-fusion-tables google-api-php-client

此代码应在经过身份验证的客户端上添加新表:

$client = new Google_Client();

$client->setClientId($config['client_id']);
$client->setClientSecret($config['client_secret']);
$client->setRedirectUri($config['redirect_uri']);
$client->setScopes(
    array(
        'https://www.googleapis.com/auth/plus.login', 
        'https://www.googleapis.com/auth/fusiontables'
    )
);
$client->setAccessToken($_SESSION['access_token']);

$fusionTablesService = new Google_Service_Fusiontables($client);

$table = new Google_Service_Fusiontables_Table();
$table->setName('testTable');

$column = new Google_Service_Fusiontables_Column();
$column->setName('testColumn');
$column->setType('STRING');

$table->setColumns(array($column));

$fusionTablesService->table->insert($table); 

但事实并非如此。我刚收到500错误:

Fatal error: Uncaught exception 'Google_Service_Exception' 

with message 

'Error calling POST https://www.googleapis.com/fusiontables/v1/tables: 
(500) Backend Error' 

in 

/vendor/google/apiclient/src/Google/Http/REST.php on line 79 

我可以追溯到最后一行:$fusionTablesService->table->insert($table);

我一直在研究和尝试6个小时,但文档很糟糕。

有人知道发生了什么吗?

1 个答案:

答案 0 :(得分:2)

似乎我所要做的就是将isExportable设置为true$table->setIsExportable('true');)。这是代码工作:

$client = new Google_Client();

$client->setClientId($config['client_id']);
$client->setClientSecret($config['client_secret']);
$client->setRedirectUri($config['redirect_uri']);
$client->setScopes(
    array(
        'https://www.googleapis.com/auth/plus.login', 
        'https://www.googleapis.com/auth/fusiontables'
    )
);
$client->setAccessToken($_SESSION['access_token']);

$fusionTablesService = new Google_Service_Fusiontables($client);

$table = new Google_Service_Fusiontables_Table();

$table->setName('testTable');

//missing line that was causing the trouble
$table->setIsExportable('true');

$column = new Google_Service_Fusiontables_Column();
$column->setName('testColumn');
$column->setType('STRING');

$table->setColumns(array($column));

$fusionTablesService->table->insert($table);