How to authorize users of gmail add-on to access https://www.googleapis.com/aut

23 views
Skip to first unread message

Ben Snowden

unread,
May 24, 2019, 5:00:57 PM5/24/19
to Google Apps Script Community
Hi,
I have a gmail add-on I wrote that creates new drafts based details about the sender. I need to use the admin directory api to get the first name and last name of the sender. The add-on works fine for me. I have enabled the admin directory api in advanced services and added the https://www.googleapis.com/auth/admin.directory.user.readonly scope to my manifest. Other user's who install the add-on get an authorization error unless I add them as a  G Suite Admin with permissions to read users. Is there any way to not require the user to be a g suite admin in order to query the readonly api?
Thanks,
Ben

Dimu Designs

unread,
May 24, 2019, 9:26:01 PM5/24/19
to Google Apps Script Community
Nope. 

Scott Donald

unread,
May 24, 2019, 11:24:50 PM5/24/19
to google-apps-sc...@googlegroups.com
Maybe you could create a core Google sheet with your directory info with time triggered updates to the sheet that you could then draw from for your purposes. 

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-script-community.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/81af2248-5fd3-4b36-acb0-e3cef38c7c74%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ben Snowden

unread,
May 24, 2019, 11:29:22 PM5/24/19
to Google Apps Script Community
Thanks for the suggestion. I was hoping the contacts app would work but it didn't seem to query the g suite directory contacts and often timed out.

Romain Vialard

unread,
May 25, 2019, 5:24:41 AM5/25/19
to Google Apps Script Community
You simply need to use the domain_public query parameter:
https://developers.google.com/admin-sdk/directory/v1/guides/manage-users#retrieve_users_non_admin

function getUserName(email) {
 
var profile = AdminDirectory.Users.get(email, {viewType: "domain_public"});
 
return profile.name.fullName;
}

Ben Snowden

unread,
May 25, 2019, 9:46:26 PM5/25/19
to Google Apps Script Community
Thanks so much. That did the trick!
Reply all
Reply to author
Forward
0 new messages