我正在尝试检测Google表格中的更新。我正在关注Sheets API V3 documentation,并且已成功观看表单并从中获取更新。
但是我没有得到所有更新。例如,如果我在表单中进行更改,我将收到Google的更新。如果我在一分钟内做出第二次更改,我可能会或可能不会得到更新。永远不会发送第三个变更。如果我然后刷新工作表,我会立即得到更新。
我已经进行了大量测试,并且认为Google没有发送我没有收到的更新。 Google是否进行了某种限制,或者这是API中的错误?
更新 我将提供一些更多的背景信息,使我更清楚我的意思。
我正在尝试获取Google表格中更改的实际数据。以this screenshot为例,每当表单中的值发生变化时,我都希望Google将更新实时推送给我。我正在使用Google表格API来观看工作表(drive.files.watch),创建手表的工作正常,这不是问题。问题是我有时会得到更新推送,例如前两个更改将发送给我。但如果进行大量编辑,他们就永远不会被发送。
答案 0 :(得分:0)
尝试手动设置电子表格中的通知规则。您可以转到工具 - >执行此操作通知规则,点击单选按钮 "Any changes are made"
和 "Email - right away"
,即可在电子表格中发生更改时立即收到通知。
接收通知的另一种方法是创建一个检查更改的函数。请查看此SO question中的示例代码。
var sheet = **whatever**;//The spreadsheet where you will be making changes
var range = **whatever**;//The range that you will be checking for changes
var compSheet = **whatever**;//The sheet that you will compare with for changes
function checkMatch(){
var myCurrent = sheet.getRange(range).getValues();
var myComparison = compSheet.getRange(range).getvalues();
if(myCurrent == myComparison){//Checks to see if there are any differences
for(i=0;i<compSheet.length;++i){ //Since getValues returns a 'multi-dimensional' array, 2 for loops are used to compare each element
for(j=0;j<compSheet[i].length;++i){
if(myCurrent[i][j] != myComparison[i][j]){//Determines if there is a difference;
//***Whatever you want to do with the differences, put them here***
}
}
myEmailer(sheet.getUrl());//Passes the url of sheet to youur emailer function
compSheet.getRange(range).setValues(myCurrent);//Updates compSheet so that next time is can check for the next series of changes
}
}
希望它对你有所帮助。