Google drive API delete file updates the last modified date - google-api

There is a different behavior from Google Drive UI and Google Drive API, when removing a file.
Using Google Drive UI:
remove a file, it will go to trash folder and the Last Modified Date is still the same. (if user restore the file, still there is no change on last modified date)
Using Google Drive API:
delete a file, it will go to trash folder, BUT the Last Modified date is changed and if user restore the file, there will be a new modified date.
to me API behavior is more correct, because there is an action made to the file, therefore modified date should change, but how come Google UI doesn't change the Last Modified date ?
Thanks,

This does appear to be an inconsistency between the UI and the API, although what the correct behavior should be is debatable. I've reached out the engineering team to see if they can bring the two paths inline. In the meantime, you can trash a file without changing the modifiedDate by instead using a Files.patch() request and setting the modifiedDateBehavior parameter to "noChange":
PATCH https://www.googleapis.com/drive/v2/files/...?modifiedDateBehavior=noChange
{
"labels": {
"trashed": true
}
}

Related

Google Drive Files/Spreadsheets REST API: How to avoid delay when tracking file changes?

I have an application where I need to keep local copies of some of my user's Google Spreadsheets, and this copy should be in sync with the Google Drive version. I've been testing two methods of tracking changes to a Google Spreadsheet: (1) the file version polling method and (2) the files.watch method.
1) The file version polling method
In this method, whenever I need the most recent version of a Spreadsheet (for instance, when the user wants to download the file from my application), I retrieve the file version from Google using:
POST https://www.googleapis.com/drive/v3/files/FILE_ID?fields=version
If the version is greater than the version I have stored on my end, I know that changes have been made and the file on my end is outdated. So I download the file and update my copy.
The problem is that it takes a while for the file version number to be updated on Google's end. Ideally, after editing a Google Spreadsheet cell, my application should be able to detect this change within less than 10 seconds. However, after editing a cell and seeing the Saved to Drive confirmation at the top, sometimes it takes seconds, other times it takes minutes before the version number gets updated, so it is very inconsistent.
Aside from the version number, I've also tried polling the modifiedTime value to see if it changed sooner, but it didn't. So I tried another method.
2) The files.watch method
In this method, I keep track of the file changes by registering a webhook to receive change notifications from Google:
POST https://www.googleapis.com/drive/v3/files/FILE_ID/watch
Whenever I receive a change notification, I know that I need to update my local copy.
Unfortunately, the change notifications also don't happen as quick as I would like. It also has very inconsistent delays: sometimes taking a few seconds, sometimes taking more than a minute.
UPDATE (3) The 'always export' method? Never cache method?
To complicate matters, it seems that even if I ignore my local copy and always try to download the latest version of the file directly from Google, the downloaded file will not necessarily be the absolute latest version that the user sees on the Spreadsheets editor. I tried that using
GET https://www.googleapis.com/drive/v3/files/FILE_ID/export?mimeType=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
but it would often return the outdated version, and sometimes would only return the latest version after a few minutes.
Is there something else that I can try? The above methods use the Google Drive Files API, but if there is a way to detect changes sooner using the Google Spreadsheets API, I would like to know.
1. How to detect file changes as soon as possible?
After a file change (in my case, a change in a Google Spreadsheet), the version does not get updated immediately, and when you watch for file changes with the files.watch API you will also not get a notification immediately.
What does get updated immediately is the list of revisions of the file, which can be retrieved with the revisions.list API:
GET https://www.googleapis.com/drive/v3/files/FILE_ID/revisions
This returns a list of all revisions of the file FILE_ID. The last item in the list is the most recent revision (the "head" revision). In order to know if a file has changed, I retrieve this list. If the id of head revision is different from the id stored in my end, it means that my local copy is outdated, so I have to update the file and its revision id.
However, if you call files.export, the file version returned will not necessarily be the absolute most recent version (e.g., the Google Sheet you are seeing in your browser). And in the case of Google editor documents, it is not possible to retrieve the most recent revision using the revisions.get API. What can you do then?
2. How to retrieve the most recent revision of a Google Sheet?
(I bet it works for other Google editor documents as well).
Before calling files.export, you have to "touch" the file using the files.update API, updating its modifiedTime:
PATCH https://www.googleapis.com/drive/v3/files/fileId
{
"modifiedTime": "TIMESTAMP"
}
Where TIMESTAMP is a date with the format 2022-04-16T22:00:00Z.
For some reason, touching the file like this "forces" Google to return the head revision of the file the next time you call files.export:
GET https://www.googleapis.com/drive/v3/files/FILE_ID/export?mimeType=MIMETYPE
In my case, MIMETYPE is application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.
That's it. So far, this has been working for me.

Google Drive API (REST) - Get download, files views and so on....?? (Is it possible??)

This is documentation which I'm using - https://developers.google.com/drive/api/v3/search-parameters
Does anyone know the way of getting through Google Drive API, the number of times the file was downloaded, views(ideal views by whom)...
I could not find any way of doing this.
Google drive files are denoted by a file resource this contains all the information that you have access to about the file. Only some of the information you are after is available
createdTime datetime The time at which the file was created (RFC 3339 date-time). writable
modifiedTime datetime The last time the file was modified by anyone (RFC 3339 date-time).
Note that setting modifiedTime will also update modifiedByMeTime for the user.
lastModifyingUser nested object The last user to modify the file.
You can see who last changed the file but you cant see who has seen the file or any information about how many times it was downloaded.

How do I differentiate whether the change triggered is a file upload/update/trash from the change object provided by google API?

We are using the push notifications provided by google Drive API. The change id is pushed to the service by google, and we use the GET Api to retrive the change object. Our requirement is to find from the change object whether it is a file upload/update or trash. We tried using created date, modified date and modification date to find the difference. But the modification date is not providing the time the change happened originally and there is a difference of 2 seconds sometimes.. Also, When a folder is shared to multiple users, for the same change, the modification date which each user receive is different from that of the other and the difference is in seconds.
Please suggest if there is a way to distinguish between file upload/update/trash from change object.
Also, provide inputs on why the modification date is different for each user, and different from file modified date.
NOTE: We cannot use watch for files as per our requirement as there are lot of files in the drive and we can watch only for changes in the entire drive.

Mixpanel — delete user with all past data

I'm working on adding Mixpanel for my project. After logging some crappy data at first, I deleted the user from Mixpanel, deleted it from my test database, and gone through registration again.
However, since I used DeviceUDID as Mixpanel's distinct id, it was the same for the new user — and when I opened Mixpanel, I saw the deleted user ressurected, with all old data and events in his profile.
How can I delete this old user forever?
yes, you can delete a user permanently from Mixpanel. Here is how:
{
"$token": "YOUR_TOKEN",
"$distinct_id": "DISTINCT_ID_TO_REMOVE",
"$delete": ""
}
You have to encode it in Base64 (e.g. with this tool: https://www.base64encode.org/) and append the base64-encoded data as url parameter to http://api.mixpanel.com/engage/
The example would look like this: http://api.mixpanel.com/engage/?data=ew0KICAgICIkdG9rZW4iOiAiWU9VUl9UT0tFTiIsDQogICAgIiRkaXN0aW5jdF9pZCI6ICJESVNUSU5DVF9JRF9UT19SRU1PVkUiLA0KICAgICIkZGVsZXRlIjogIiINCn0=

Sync mailchimp campaign click and open with some other database

I am working on mailchimp integration.
I need to pull campaign stats (opens and clicks) and put it in my local database.
Using mailchimp api i am getting the list of all the users with their action taken.
But my issue is how to keep data sync at all time.
Is there any way to skip that data from mailchimp api that i had synced already.
The problem is the entire data set can change between calls and there is no 'since' parameter... The only way to get an updated picture is to query all records and update....
Keeping stat "data synced at all times" really would just depend on your solution (have it query for updates when you/your users access that section...)
You could expidite the update process by keeping track of previous calls/updates with the timestamp (keep track of the timestamp and only update/add records that are newer than the last sync... )
As I said, there is currently no "since" command for the campaignEmailStatsAIMAll method (and no direct equivelent in the export API...)
A 'since' parameter would actually be a good feature... So if coding your own solution to track updates via the timestamp is undesirable, you may want to ask the question in the google group or post a feature request in the google code project:
http://code.google.com/p/mailchimp-api/
EDIT: I just opened the feature request as it may solve a similar issue for an upcomming project:
http://code.google.com/p/mailchimp-api/issues/detail?id=60

Resources