訪問者が情報を入力して、(mysql データベースではなく) Google Fusion テーブルに直接投稿できるページを設定しようとしています。
Google が古い Fusion Tables SQL API を廃止すると聞いたので、Fusion Tables API v.1 に準拠したものが必要です INSERT INTO <tableid> (column name) VALUES (user-input response)
。これを何度も繰り返しましたが、成功していません。
最終的に、基本的なフォーム入力のサンプル コードを融合テーブルにコピーし、値を独自のサンプル テーブルに変更することにしました。これはまだ機能していません。これが私のコードです-この分野である程度の経験を持つ誰かが評価できることを願っています。自分が何をしているのか本当にわからない、と思います。
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { font-family: Arial; }
</style>
<script src="https://apis.google.com/js/client.js?onload=initialize"></script>
<script type="text/javascript">
// The clientId and apiKey are available at
// https://code.google.com/apis/console. For more information, see
// http://code.google.com/p/google-api-javascript-client/wiki/Authentication.
var clientId = '424838770953.apps.googleusercontent.com';
var apiKey = 'AIzaSyBGFOBBGu5x2LuCNmDIvfe-FEPtq--tRPI';
var scopes = 'https://www.googleapis.com/auth/fusiontables';
var tableId = '1c9tCQTEOog66RXBCQxNjmHDERbIJxuAm5SgBhSs';
// Initialize the client, set onclick listeners.
function initialize() {
gapi.client.setApiKey(apiKey);
document.getElementById('insert-data').onclick = insertData;
window.setTimeout(function() { auth(true); }, 1);
}
// Run OAuth 2.0 authorization.
function auth(immediate) {
gapi.auth.authorize({
client_id: clientId,
scope: scopes,
immediate: immediate
}, handleAuthResult);
}
// Handle the results of the OAuth 2.0 flow.
function handleAuthResult(authResult) {
var authorizeButton = document.getElementById('authorize-button');
var createTableButton = document.getElementById('create-table');
if (authResult) {
authorizeButton.disabled = true;
createTableButton.disabled = false;
} else {
authorizeButton.disabled = true;
authorizeButton.onclick = function() { auth(false); return false; };
}
}
// Run a request to INSERT data.
runClientRequest({
path: '/fusiontables/v1/tables',
method: 'POST'
}, function insertData() {
var name = document.getElementById('name').value;
var age = document.getElementById('age').value;
var insert = [];
insert.push('INSERT INTO ');
insert.push('1c9tCQTEOog66RXBCQxNjmHDERbIJxuAm5SgBhSs');
insert.push(' (Name, Age) VALUES (');
insert.push("'" + name + "', ");
insert.push(age);
insert.push(')');
body: 'insert'
}
// Execute the client request.
function runClientRequest(request, callback) {
var restRequest = gapi.client.request(request);
restRequest.execute(callback);
}
</script>
</head>
<body>
<h1>
Fusion Tables JavaScript Example
</h1>
<h2>
(3) Insert data
</h2>
<p>
Insert data into the newly created table.
</p>
<pre>INSERT INTO <span id="table-id-1">[table_id]</span> (Name, Age) VALUES ([name],
[age])</pre>
<label>Name:</label>
<input type="text" id="name"><br>
<label>Age:</label>
<input type="age" id="age"><br>
<input type="button" id="insert-data" value="Insert data">
<p id="insert-data-output"><i>insert response goes here...</i></p><br>