1

请如果有人可以帮助我找到一种方法来开发一个功能,让我通过我的应用程序phoneGap(和sencha)访问我的谷歌驱动器的帐户并创建我自己的表(谷歌融合表);我找到了一个文件 javascript:

    <!DOCTYPE html>
<!--
  Copyright 2011 Google Inc. All Rights Reserved.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<html>
  <head>
    <title>JavaScript API Example</title>

    <style type="text/css">
      body { font-family: Arial; }
    </style>
    <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 = '958693490238-nti7k45ajor0287286o8a5p4m26um32n.apps.googleusercontent.com';
      var clientSecret = 'p--MYTDoaqliiiSmP4TPFZX5';
      var apiKey = 'AIzaSyCa_oJyC4vX1KAbNoi0n0Zyqf_ZWTp8J7U';
      var scopes = 'https://www.googleapis.com/auth/fusiontables';
      var tableId;

      // Initialize the client, set onclick listeners.
      function initialize() {
        gapi.client.setApiKey(apiKey);
        document.getElementById('create-table').onclick = createTable;
        document.getElementById('insert-data').onclick = insertData;
        document.getElementById('select-data').onclick = selectData;
        window.setTimeout(function() { auth(true); }, 1);
      }

      // Run OAuth 2.0 authorization.
      function auth(immediate) {
        gapi.auth.authorize({
          client_id: clientId,
          client_secret: clientSecret,
          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 = false;
          authorizeButton.onclick = function() { auth(false); return false; };
        }
      }

      // Run a request to create a new Fusion Table.
      function createTable() {
        var tableResource = [];
        tableResource.push('{');
        tableResource.push('"name": "People",');
        tableResource.push('"columns": [');
        tableResource.push('{ "name": "Name", "type": "STRING" },');
        tableResource.push('{ "name": "Age", "type": "NUMBER" }');
        tableResource.push('],')
        tableResource.push('"isExportable": true');
        tableResource.push('}');
        runClientRequest({
          path: '/fusiontables/v1/tables',
          body: tableResource.join(''),
          method: 'POST'
        }, function(resp) {
          var output = JSON.stringify(resp);
          document.getElementById('create-table-output').innerHTML = output;
          tableId = resp['tableId'];
          document.getElementById('table-id-1').innerHTML = tableId;
          document.getElementById('table-id-2').innerHTML = tableId;
          document.getElementById('insert-data').disabled = false;
          document.getElementById('select-data').disabled = false;
          document.getElementById('create-table').disabled = true;
        });
      }

      // Run a request to INSERT data.
      function insertData() {
        var name = document.getElementById('name').value;
        var age = document.getElementById('age').value;
        var insert = [];
        insert.push('INSERT INTO ');
        insert.push(tableId);
        insert.push(' (Name, Age) VALUES (');
        insert.push("'" + name + "', ");
        insert.push(age);
        insert.push(')');
        query(insert.join(''));
      }

      // Run a request to SELECT data.
      function selectData() {
        query('SELECT * FROM ' + tableId);
      }

      // Send an SQL query to Fusion Tables.
      function query(query) {
        var lowerCaseQuery = query.toLowerCase();
        var path = '/fusiontables/v1/query';
        var callback = function(element) {
          return function(resp) {
            var output = JSON.stringify(resp);
            document.getElementById(element).innerHTML = output;
          };
        }
        if (lowerCaseQuery.indexOf('select') != 0 &&
            lowerCaseQuery.indexOf('show') != 0 &&
            lowerCaseQuery.indexOf('describe') != 0) {

          var body = 'sql=' + encodeURIComponent(query);
          runClientRequest({
            path: path,
            body: body,
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded',
              'Content-Length': body.length
            },
            method: 'POST'
          }, callback('insert-data-output'));

        } else {
          runClientRequest({
            path: path,
            params: { 'sql': query }
          }, callback('select-data-output'));
        }
      }

      // Execute the client request.
      function runClientRequest(request, callback) {
        var restRequest = gapi.client.request(request);
        restRequest.execute(callback);
      }
    </script>
    <script src="https://apis.google.com/js/client.js?onload=initialize"></script>
  </head>
  <body>
    <h1>
      Fusion Tables JavaScript Example
    </h1>
    <h2>
      (1) Authorize using OAuth 2.0
    </h2>
    <p>
      Click Authorize to start the OAuth 2.0 authorization flow. If you have
      already authorized, the button will be disabled.
    </p>
    <input type="button" id="authorize-button" value="Authorize"><br>

    <h2>
      (2) Create Table
    </h2>
    <p>
      Click "Create Table" to create an exportable Fusion Table called "People"
      with columns "Name" with type "STRING" and "Age" with type "NUMBER".
      <pre>
{
  "name": "People",
  "columns": [
    {
      "name": "Name",
      "type": "STRING"
    }, {
      "name": "Age",
      "type": "NUMBER"
    }
  ],
  "isExportable": true
}</pre>
    </p>
    <input type="button" id="create-table" value="Create Table"
        disabled="disabled">
    <p id="create-table-output"><i>table response goes here...</i></p><br>

    <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"
        disabled="disabled">
    <p id="insert-data-output"><i>insert response goes here...</i></p><br>

    <h2>
      (4) Select all the rows from the table
    </h2>
    <p>
      Select the data that has been inserted into the newly created table.
    </p>
    <pre>SELECT * FROM <span id="table-id-2">[table_id]</span></pre>
    <input type="button" id="select-data" value="Select data"
        disabled="disabled">
    <p id="select-data-output"><i>select response goes here...</i></p>
  </body>
</html>

然后我将它与我自己的客户端 id 和 apiKey 集成到我的应用程序 sencha(在 localhost 中),它可以工作,但是当我将它部署到我的设备 android 中时它不会 :( 我知道我的设备没有检测到帐户的信息(我的 gmail 帐户在设备中处于活动状态,但没有出现授权页面)。

请帮忙!

4

0 回答 0