Search code examples
javascriptgoogle-apps-scriptgoogle-apigoogle-drive-apigoogle-people-api

How to find the email address of an external user to the domain based on their unique ID using Google People API


I'm using Google Apps Script to call the Google API 'https://driveactivity.googleapis.com/v2/activity:query', which returns a JSON response in the following format:

{
  "activities": [
    {
      "primaryActionDetail": {
        "permissionChange": {
          "addedPermissions": [
            {
              "role": "EDITOR",
              "user": {
                "knownUser": {
                  "personName": "people/11xxxxxxxxxx6"
                }
              }
            }
          ]
        }
      },
      "actors": [
        {
          "user": {
            "knownUser": {
              "personName": "people/11xxxxxxxxxxx8",
              "isCurrentUser": true
            }
          }
        }
      ],
      "actions": [
        {
          "detail": {
            "permissionChange": {
              "addedPermissions": [
                {
                  "role": "EDITOR",
                  "user": {
                    "knownUser": {
                      "personName": "people/115xxxxxxxxxxx6"
                    }
                  }
                }
              ]
            }
          }
        }

I want to find the email address of a user outside the domain with the ID 'people/11xxxxxxxxxx6'. I've tried using the API 'https://people.googleapis.com/v1/people', but it only returns:

{
"resourceName": "people/11xxxxxxxxxx36",
"etag": "%EgUBCS43PhoEAQIFByIMNy9sNFRaW"
}

Is there a way to retrieve the email address using a Google Apps Script?"


Solution

  • I have found a solution to my previous question. Instead of using the Drive Activity API, I can use the API "GET https://admin.googleapis.com/admin/reports/v1/activity/users/all/applications/drive?eventName=change_user_access". This API provides me with more information than the Drive Activity API. Thank you for your help.