必须同时提供 client_id 和 range 来初始化 OAuth

ice*_*ter 6 javascript google-sheets-api

我正在使用Google Sheets API Javascript 快速入门,并遇到了gapi.client.init().

这是给我带来问题的代码:

// Client ID and API key from the Developer Console
var CLIENT_ID = "50m3-cle3nt-1d.apps.googleusercontent.com";
var API_KEY = "AIzaN0tRe4lLyAn4pIk5y";

// Array of API discovery doc URLs for APIs used by the quickstart
var DISCOVERY_DOCS = ["https://sheets.googleapis.com/$discovery/rest?version=v4"];

// Authorization scopes required by the API; multiple scopes can be
// included, separated by spaces.
var SCOPES = "https://www.googleapis.com/auth/spreadsheets.readonly";

function initClient() {
    gapi.client.init({
        apiKey: API_KEY,
        discoveryDocs: DISCOVERY_DOCS,
        clientId: CLIENT_ID,
        scope: SCOPES
    }).then(function() {
        // doesn't matter.
    })
}           
Run Code Online (Sandbox Code Playgroud)

我无法让init()呼叫正常工作,即使我尝试init()在控制台内自行呼叫,也会收到问题标题中的错误:

> k = gapi.client.init({ ... })
client_id and scope must both be provided to initialize OAuth
Run Code Online (Sandbox Code Playgroud)

我在通话中缺少什么init()

任何提示将不胜感激。

Yus*_*eff 6

我也面临同样的问题。在initClient我替换gapi.client.init为的函数中gapi.auth2.init ,它起作用了。