このコードは、認証されたクライアントに新しいテーブルを追加する必要があります。
$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時間調査と試行を続けてきましたが、ドキュメントはひどいものです。
誰かが何が起こっているのか知っていますか?
()に設定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);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加