1

I am using node js google drive meta data readonly and spreadsheet scope for reading data with google API v4. But how to get last updated rows , columns and data that has been updated in a sheet ?

****Update**

var fetchChanges = function(pageToken,pageFn, callback) {
                                service.changes.list({
                                    auth:oauth2Client,
                                    pageToken: pageToken,
                                    fields: 'kind,nextPageToken,newStartPageToken,changes(kind,type,time,removed,fileId,file,teamDriveId,teamDrive)'           
                                }, function (err, res) {
                                    if (err) {
                                        console.log("------err in service.changes : " ,err);
                                        return;
                                    } else {
                                        console.log("change resp : ", res.changes);
                                        // Process changes
                                        res.changes.forEach(function (change) {
                                            console.log("Change found for file: ", change.fileId);
                                        });

                                        if (res.newStartPageToken) {
                                            // Last page, save this token for the next polling interval
                                            callback(null, res.newStartPageToken);
//                                           console.log("--------newStartPageToken : ",res.newStartPageToken);
                                        }
                                        if (res.nextPageToken) {
                                            pageFn(res.nextPageToken, pageFn, callback);
                                        }
                                    }
                                });
                            };

Response I am getting in console as well as in google explorer:

{ kind: 'drive#changeList', newStartPageToken: '7911', changes: [] } }

Note changes object data not present and nextPageToken also absent.

Subhajit
  • 876
  • 3
  • 17
  • 37
  • Looking at the code, it seems to be using the Drive API, but the tags are for Google Spreadsheet API which makes things a bit confusing. Would you be able to rephrase/expound on what are the changes you're trying to get and where you're trying to use them? – AL. May 06 '17 at 07:31
  • Or were you hoping to simply get the changes for a Spreadsheet file using the Drive API without specifically knowing which row/column changed? – AL. May 06 '17 at 07:35

2 Answers2

1

I got the solution :

I have to get the future changes token at first then using that token changes done after the token creation. And remember to add the space as parameters like this:

spaces(drive,appDataFolder,photos)
FZs
  • 16,581
  • 13
  • 41
  • 50
Subhajit
  • 876
  • 3
  • 17
  • 37
0

There is currently no API you could use to directly retrieve the data from the last edit in a Spreadsheet.

As a workaround, you could implement an App Script that detects changes in the Spreadsheet, stores the data you need temporarily (to a different sheet), and then access it from there.

Also see these posts:

Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281
  • I want to know about, "how can I get the changes done to my google spreadsheet currently" through google api. You can get the api docs from here : https://developers.google.com/drive/v3/web/manage-changes . I am currently not getting newPageToken and changes resource object data. Thanks. – Subhajit May 06 '17 at 07:18
  • If you're looking for something like a *feed* of applied changes *in* the Spreadsheet, there isn't any API for it. The Drive API could see the changes applied to the file after it is modified (and saved AFAIK). You'll have to implement a script for the Spreadsheet itself to detect the changes that are *currently* being applied. – AL. May 06 '17 at 07:23
  • I guess you are not understanding. PLEASE refer the sheet developers.google.com/drive/v3/web/manage-changes – Subhajit May 06 '17 at 07:27
  • I've seen the docs. What I'm now confused of is the description of the post, plus the added code snippets. Would you be able to *explain it more clearly*? Reading through your post right now, it's just asking what changed in the Spreadsheet and how to get the changes. – AL. May 06 '17 at 07:28
  • See, I want my get my spreadsheet changes. The above snippet is of the service to get the changes after a certain time. – Subhajit May 06 '17 at 08:44