Google 工作表 API 和 Chrome 应用

Google Sheets API and Chrome Apps

我有一个应用程序使用 background.js 从 Google 表格中提取数据,但我无法在 popup.js 本身中使用该信息。我对 Chrome 应用不太熟悉,遇到这种情况我该怎么办?我如何获得 Chrome 身份或 API 以将信息传递给 popup.js?我无法在 popup.js 中实现 API 调用,因为我需要它在后台工作。

所以我想用Google张API修改一个sheet,然后读出来。

我基本上是在 background.js:

chrome.identity.getAuthToken({ 'interactive': true }, function(token) {
    var response;
    var requestURL = "https://sheets.googleapis.com/v4/spreadsheets/" + spreadsheetId + "/values/" + range;
    var objectHTTP;
    objectHTTP = new XMLHttpRequest();
    objectHTTP.onreadystatechange = function() {

    if (objectHTTP.readyState == 4 && objectHTTP.status == 200) {
            response = objectHTTP.responseText;
        }
    };

    objectHTTP.open("GET", requestURL, false);
    objectHTTP.setRequestHeader('Authorization', 'Bearer ' + token);
    objectHTTP.send();

    // This is the part where I obtain the response, but how do I use it in the main app (popup.js)? Can I somehow share the variables?
    });

您可以使用 background.js 更新另一个 sheet,然后使用您的 popup.js 从中读取。这样第二个 sheets 充当数据存储。