Google Sheets API和Chrome应用 [英] Google Sheets API and Chrome Apps
问题描述
我有一个应用程序使用background.js从Google表格中提取数据,但是我无法在popup.js本身中使用该信息.我对Chrome Apps不太熟悉,在这种情况下该怎么办?如何获取Chrome身份或API来将信息传递给popup.js?我无法在popup.js中实现API调用,因为我需要它在后台运行.
I have an app that's pulling data from Google Sheets with background.js but I am unable to use that information in the popup.js itself. I am not too familiar with Chrome Apps, what can I do in this case? How do I get Chrome Identity or the API to pass the information to popup.js? I can't implement the API call in popup.js because I need it to work in the background.
所以我想用Google Sheets API修改工作表,然后将其读取.
So I want to modify a sheet with the Google Sheets API and then read off it.
我基本上是在background.js中这样做的:
I am basically doing this in the 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来更新另一个工作表,然后使用popup.js对其进行读取.这样,第二张纸就可以用作数据存储.
You can use the background.js to update another sheet and then use your popup.js to read from it. This way the second sheets acts as data storage.
这篇关于Google Sheets API和Chrome应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!