找不到Gapi客户端javascript 404请求的实体

问题描述

我正在使用GAPI v4端点访问Google表格,我已经使用了Google快速入门中的示例,但未找到404错误的“请求的实体”。为什么会这样,为什么不应该发生,因为我使用了他们的示例代码

<!DOCTYPE html>
<html>
  <head>
    <Meta charset="UTF-8">
    <title>Application Conversion Viewer</title>
    <!-- https://electronjs.org/docs/tutorial/security#csp-Meta-tag -->
    <!-- <Meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" /> -->
    <Meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZonixN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
  </head>
  <body>
    <div id="app">

      <!--Add buttons to initiate auth sequence and sign out-->
      <button id="authorize_button" style="display: none;">Authorize</button>
      <button id="signout_button" style="display: none;">Sign Out</button>

      <pre id="content" style="white-space: pre-wrap;"></pre>

    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue-resource@1.5.1"></script>
    <script src="https://apis.google.com/js/api.js"></script>
    <script>
    new Vue({
      el: '#app',mounted () {
        var authorizeButton = document.getElementById('authorize_button');
        var signoutButton = document.getElementById('signout_button');

        /**
         *  On load,called to load the auth2 library and API client library.
         */
        function handleClientLoad() {
          gapi.load('client:auth2',initClient);
        }

        /**
         *  Initializes the API client library and sets up sign-in state
         *  listeners.
         */
        function initClient() {
          gapi.client.init({
            apiKey: 'MY-KEY',clientId: 'MY-CLIENT-ID',discoveryDocs: 'https://sheets.googleapis.com/$discovery/rest?version=v4',scope: 'https://www.googleapis.com/auth/spreadsheets.readonly'
          }).then(function () {
            console.log('SUCCESS')
            // Listen for sign-in state changes.
            gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);

            // Handle the initial sign-in state.
            updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
            authorizeButton.onclick = handleAuthClick;
            signoutButton.onclick = handleSignoutClick;
          },function(error) {
            console.log(error)
            appendPre(JSON.stringify(error,null,2));
          });
        }

        /**
         *  Called when the signed in status changes,to update the UI
         *  appropriately. After a sign-in,the API is called.
         */
        function updateSigninStatus(isSignedIn) {
          if (isSignedIn) {
            authorizeButton.style.display = 'none';
            signoutButton.style.display = 'block';
            listMajors();
          } else {
            authorizeButton.style.display = 'block';
            signoutButton.style.display = 'none';
          }
        }

        /**
         *  Sign in the user upon button click.
         */
        function handleAuthClick(event) {
          gapi.auth2.getAuthInstance().signIn();
        }

        /**
         *  Sign out the user upon button click.
         */
        function handleSignoutClick(event) {
          gapi.auth2.getAuthInstance().signOut();
        }

        /**
         * Append a pre element to the body containing the given message
         * as its text node. Used to display the results of the API call.
         *
         * @param {string} message Text to be placed in pre element.
         */
        function appendPre(message) {
          var pre = document.getElementById('content');
          var textContent = document.createTextNode(message + '\n');
          pre.appendChild(textContent);
        }

        /**
         * Print the names and majors of students in a sample spreadsheet:
         * https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit
         */
         function listMajors() {
          gapi.client.sheets.spreadsheets.values.get({
            spreadsheetId: '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms',range: 'Class Data!A2:E',}).then(function(response) {
            var range = response.result;
            if (range.values.length > 0) {
              appendPre('Name,Major:');
              for (i = 0; i < range.values.length; i++) {
                var row = range.values[i];
                // Print columns A and E,which correspond to indices 0 and 4.
                appendPre(row[0] + ',' + row[4]);
              }
            } else {
              appendPre('No data found.');
            }
          },function(response) {
            appendPre('Error: ' + response.result.error.message);
          });
        }

        console.log('LOAD')
        handleClientLoad()
      }
    })
    </script>
  </body>
</html>

我尝试了几种方法来使它起作用,但都不起作用。快速入门似乎是错误的:https://developers.google.com/sheets/api/quickstart/js

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...