Domain profile pics

232 views
Skip to first unread message

Martin MULLAN

unread,
Jun 20, 2021, 9:23:08 PM6/20/21
to Google Apps Script Community
Hi all,
I am trying to retrieve the logged in user's profile pic in a htmlservice apps script page...it is proving harder than I would have thought.
Anyone got the code that retrieves the url for the profile pic based on a user's email address so I can present a list of users with their pic e.g. for a class of students?
Cheers, Mart.

Faustino Rodriguez

unread,
Jun 21, 2021, 8:09:05 AM6/21/21
to Google Apps Script Community
you can get that picture url server-side and pass it to theh htmlservice page to show it
In code below, userinfo would include the user's picture (if any) and other details from the user profile

    //  var user = Session.getEffectiveUser().getEmail(); // only to include scope https://www.googleapis.com/auth/userinfo.email
    var param = {
      method : "get",
      headers : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
    };
    var response = UrlFetchApp.fetch(url, param);
    let code = response.getResponseCode();
    let content = response.getContentText();
    var userinfo = JSON.parse(content);



Martin MULLAN

unread,
Jun 21, 2021, 6:28:00 PM6/21/21
to Google Apps Script Community
Thanks Faustino, that works, and I see you have answered that before!

Different question. I have a list of email addresses in a sheet. I need to return the profile pic url for the email address, not the logged in user. Can you help with this?


Faustino Rodriguez

unread,
Jun 22, 2021, 10:30:31 AM6/22/21
to Google Apps Script Community
I believe that's not possible or at least I don't how to do that
To access that information with a script (either server or client side) you'd need the user's authorization

Manually, you can mouse over the email address in your datasheet
- and right-click the user's image to get the image address, if the user has a photo
- but that might be a temporary Url as it's based on googleusercontent server

Optionally, and this is a wild guess,
- you can add all those emails as Contacts with an specific label and then
- you can explore the Advanced People Service (People API) to see if you can get their photo's Url from there
- let us know if that works, just in case it can help others

Reply all
Reply to author
Forward
0 new messages