2016-08-03 75 views
2

我在嘗試設置與Google電子表格的雙向同步。我可以用它Google Sheets API V4從Google電子表格接收實時更新

現在在推我的數據集的谷歌電子表格的變化,我希望能夠從谷歌電子表格獲取更新,每當有人進行編輯或在實時或近實時添加新行-時間。

任何幫助指出我在正確的方向是非常感謝。

回答

1

您可以通過工具 - >通知規則手工做..

enter image description here

如果該文件是在谷歌驅動器,你可以嘗試使用Push Notifications: 要使用推送通知,您需要做三件事:

註冊您的接收URL的域。例如,如果您打算將 用作//mydomain.com/notifications作爲您的接收URL,則需要 註冊//mydomain.com。設置您的接收URL或「Webhook」回撥接收器。這是一個HTTPS服務器,用於處理資源更改時觸發的API 通知消息。設置 爲您想要的每個資源端點註冊一個通知通道。一個通道爲通知 指定路由信息。作爲頻道設置的一部分,您需要確定要接收通知的特定網址 。只要通道的資源 發生更改,Drive API就會將該通知消息作爲POST請求 發送到該URL。

Google walkthrough video here

你也可以使用Appscript。這個簡單的黑客是從這個SO thread

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 
    } 
    } 
+0

「推送通知」是我所需要的;謝謝! – user4426017

+0

你能告訴我如何爲特定文件創建頻道嗎? –

相關問題