gpt4 book ai didi

javascript - 为什么gapi.client.init(Google Drive API)不起作用?

转载 作者:行者123 更新时间:2023-11-28 04:15:46 25 4
gpt4 key购买 nike

我正在通过 JavaScript 使用 Google Drive API 进行开发。我尝试了示例代码,发现它工作正常。但是,相同的代码不适用于 chrome 扩展。我猜这是客户端 ID 值的问题,但我不认为这很奇怪,为什么它不能与 Chrome 扩展一起使用?

  // Client ID and API key from the Developer Console
var CLIENT_ID = '467319036759-udrp5jb3257p1kd11n5016rdid4qm8kd.apps.googleusercontent.com';

// Array of API discovery doc URLs for APIs used by the quickstart
var DISCOVERY_DOCS = ["https://www.googleapis.com/discovery/v1/apis/drive/v3/rest"];

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

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);
console.log("load ok");
}

/**
* Initializes the API client library and sets up sign-in state
* listeners.
*/
function initClient() {
gapi.client.init({
discoveryDocs: DISCOVERY_DOCS,
clientId: CLIENT_ID,
scope: SCOPES
}).then(function () {
// Listen for sign-in state changes.
console.log("client ok");
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);
});

console.log("client");
}

enter image description here

控制台日志不显示“客户端正常”

我注册的扩展地址是https://chrome.google.com/webstore/detail/study/minmfnjifbdpcphgildjgfpnbiejajml

最佳答案

关于javascript - 为什么gapi.client.init(Google Drive API)不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45859065/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com