0

I have a Google Spreadsheet and I need to get the current user's email address in it.

I can't use GAS + Session.getActiveUser().getEmail() since that requires auth/permissions.

So my thought is to use one of the IMPORT functions to import data from some URL/API that'll return the current user's email address.

IMTheNachoMan
  • 5,343
  • 5
  • 40
  • 89

1 Answers1

1

People api and user profile info

The direct way to get a users email address is to request the email scope and go though the people api.

The people get method will return the users email address if you have authroized the user with the email scope.

Again the draw back to this method is you need to request permission of the user to see their email address.

Drive api current users email

Some of the Google apis actually return the email without requiring that you ask the users permission to see their email.

If you are requesting one of the google drive scopes which you may be if your using a google sheet api. Calling about get will return the users email address

{
  "kind": "drive#about",
  "user": {
    "kind": "drive#user",
    "displayName": "Linda Lawton",
    "photoLink": "https://lh3.googleusercntent.com/a-/AOh14GhroCYJp2P9xeYeYk1npchBPK-zbtTxzNQo0WAHI20=s64",
    "me": true,
    "permissionId": "030588225573437243",
    "emailAddress": "XX@gmail.com"
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449