Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用访问令牌获取googlesheet数据?_Javascript_Google Sheets_Fetch - Fatal编程技术网

Javascript 使用访问令牌获取googlesheet数据?

Javascript 使用访问令牌获取googlesheet数据?,javascript,google-sheets,fetch,Javascript,Google Sheets,Fetch,我想获取谷歌的数据。通过我的代码,我可以获得访问令牌,但现在我不知道如何使用javascript中的特定访问令牌获取googlesheet中的所有记录。 我已将清单中的范围指定为电子表格.readonly。 我在一个特定变量中有我的令牌,在另一个变量中也有googlesheeetId,现在我需要paas的哪些标题和url,这样我才能获得googlesheet数据。 请提供一些参考资料、链接或示例代码,以便我可以大致了解执行此操作需要遵循的流程 这是代码 var gSheetId; chrome

我想获取谷歌的数据。通过我的代码,我可以获得访问令牌,但现在我不知道如何使用javascript中的特定访问令牌获取googlesheet中的所有记录。 我已将清单中的范围指定为电子表格.readonly。 我在一个特定变量中有我的令牌,在另一个变量中也有googlesheeetId,现在我需要paas的哪些标题和url,这样我才能获得googlesheet数据。 请提供一些参考资料、链接或示例代码,以便我可以大致了解执行此操作需要遵循的流程

这是代码

var gSheetId;

chrome.identity.getAuthToken({ 'interactive': true }, function (token) {
  if (chrome.runtime.lastError) {
    console.log(chrome.runtime.lastError);
    return;
  }
  console.log(token);

  //getting googlesheetId from user
  gSheetId = prompt("Please provide your googlesheet Id");
  if (!gSheetId) {
    alert("Operation Cannot be Performed! Please refresh");
  } 
  else {
    //read googlesheetdata
    var headers = {
      'Authorization':'Bearer '+token
    }
    //here I need to read the googlesheet data using the token
    chrome.debugger.onEvent.addListener(onEvent);
  }
});
提前感谢

解决方案 由oiginal问题的所有者@StayAtOrbit为您带来。(这是一个社区维基答案)

这一问题的有用资源:

var gSheetId;
chrome.identity.getAuthToken({'interactive':true},函数(token){
if(chrome.runtime.lastError){
log(chrome.runtime.lastError);
返回;
}
console.log(令牌);
//从用户处获取googlesheetId
gSheetId=prompt(“请提供您的谷歌表单Id”);
如果(!gSheetId){
警报(“无法执行操作!请刷新”);
} 
else{//读取googlesheetdata
var obj={
方法:“GET”,
标题:{
“接受”:“应用程序/json”,
“内容类型”:“应用程序/json”,
“主机”:“sheets.googleapis.com”,
“授权”:“持票人”+代币
}
}
取('https://sheets.googleapis.com/v4/spreadsheets//values/",obj)
.然后(功能(res){
返回console.log(res.json());
}).then(函数(resJson){
返回console.log(resJson);
})
//在这里,我需要使用令牌读取googlesheet数据
chrome.debugger.onEvent.addListener(onEvent);
}

});你试过了吗?在那里,您可以找到一个设置,其中包含一些关于如何使用JavaScript客户端访问google工作表的文档。另外,为了确定,您是否打算使用JavaScript或应用程序脚本?好的!让我编辑我的问题!您希望获取什么类型或格式的数据?@StayAtOrbit这是用于什么应用程序的?一个浏览器或者你正在尝试做一个Chrome扩展?我在下面运行了一个应用程序,如果你要找的是一个简单的JavaScript应用程序,我可以向你展示如何从一张纸上获取数据,并给出这个问题的答案