必须同时提供client_id和范围才能初始化OAuth

时间:2017-05-07 11:19:56

标签: javascript google-sheets-api

我正在使用Google Sheets API Javascript Quickstart,并遇到了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.
    })
}           

即使我尝试在控制台内单独调用init(),我也无法让init()调用工作,并且我会在问题标题中收到错误:

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

init()来电中我错过了什么?

任何提示都将不胜感激。

0 个答案:

没有答案