Folder moving events in google drive

187 Views Asked by At

When I drag a folder to another location,

is there any way I could know this activity, telling me that it is from where to where?

1

There are 1 best solutions below

2
Ron M On

Use Google Drive Activity API to get informations about the changes made within a user's Google Drive.

Using activity.query():

  • Set the itemName based on the file/folder that you want to check activity using this format "items/FILE_ID" or "items/FOLDER_ID"
  • Set filter to detail.action_detail_case:MOVE to get move action activities

References:


Sample Request Body:

{
  "filter": "detail.action_detail_case:MOVE",
  "itemName": "items/1BNPRFAJgVMW-DF_sdEsF-_14X0xxxxx"
}
  • Filter all drive activity that has move ActionDetail
  • Primary criteria is to return activities for a specific folder with folder id: 1BNPRFAJgVMW-DF_sdEsF-_14X0xxxxx

Response Body:

This will return a DriveActivity object that will contain a Move object under ActionDetail object. You can refer to the removedParents->driveItem to get the information regarding the previous parent folder of the file/folder and addedParents->driveItem to get the new parent folder of the file/folder

{
  "activities": [
    {
      "primaryActionDetail": {
        "move": {
          "addedParents": [
            {
              "driveItem": {
                "name": "items/1mF5a3gxiLzVIRe2dhY4W3Alfxxxx",
                "title": "NewFolder_Name",
                "folder": {
                  "type": "STANDARD_FOLDER"
                },
                "driveFolder": {
                  "type": "STANDARD_FOLDER"
                }
              }
            }
          ],
          "removedParents": [
            {
              "driveItem": {
                "name": "items/1lFzVvlBnBi-2o1VQGF5JDFRxxxxx",
                "title": "TESTFOLDER",
                "folder": {
                  "type": "STANDARD_FOLDER"
                },
                "driveFolder": {
                  "type": "STANDARD_FOLDER"
                }
              }
            }
          ]
        }
      },
        
      .....
        
      "targets": [
        {
          "driveItem": {
            "name": "items/11TrX6KcAJppWCj9GSUjSYn79Aqxxxx",
            "title": "CSVFOLDER",
            "folder": {
              "type": "STANDARD_FOLDER"
            },
            "mimeType": "application/vnd.google-apps.folder",
            .......
          }
        }
      ],
      "timestamp": "2021-08-12T16:10:24.744Z"
    }
  ]
}