0

I'm building an add on that users have to subscribe to, yet because of privacy, user details like email addresses aren't accessible.

I have used Properties Service to try to get users email addresses. It works only for me, but not for others. This is a problem because there's no way I can verify who is a premium user and who is a normal user. My main challenge is in understanding how other addon deevlopers have succeeded in achieving this

var userEmail = Session.getActiveUser().getEmail();

var userProperties = PropertiesService.getUserProperties();

userProperties.setProperty("email", userEmail);

var email = userProperties.getProperty("email")
Logger.log(email) // Nothing is logged to the console or writing email to DB fails

I expect to have access to users email, write those emails to my database, but I get an empty string

How do I achieve this status for my addon. I would prefer a detailed solution. Thanks in advance

  • Are you being able to retrieve userEmail variable? How are you able to see the logs if you're not using Stackdriver Logging (https://developers.google.com/apps-script/guides/logging) with the console class (https://developers.google.com/apps-script/reference/base/console)? In any case, you don't need to use the user properties to write the emails in your DB. – Andres Duarte Aug 21 '19 at 10:06
  • Thank you @AndresDuarte. This is what I hadn't figured out. What I needed to change was my logging. From Logger.log to console.log. Also, I needed to change the default GCP project to a standard GCP project to be able to view the logs. I also needed to access my db properly. All those changes, and now, I can access and write emails to my DB. Thank you – Ojo-Femi Oma-Victor Aug 24 '19 at 04:03

1 Answers1

0

To get email of user email you have to use the getEffectiveUser(), so your code become :

var userEmail = Session.getEffectiveUser().getEmail();

Now you will have email of connected user and can check if the email have a license or not.

Be careful if you want to manage licenses you will have to use an external source to store the data. You can't access a user property. For me 2 ways : External

  1. Database on any cloud provider, GCP, firebase etc...
  2. You can create ascript you execute as a library that store users with license in a script property but you will not have lot of space to store users.

Stéphane

St3ph
  • 2,232
  • 17
  • 17
  • If that help don't forget to set as best answer for next person with this issue. My pleasure. – St3ph Aug 24 '19 at 12:40