Joy Biswas
Joy Biswas

Reputation: 6527

How to get Google workspace/gsuite user profile picture via email id

I have a list of users imported from a 3rd party LDAP and they only give me an email id and name which belongs to their organisation G-Suite or Workspace. I want to derive the profile image of the user using the email id just as gravatar does.

I have tried using Nodejs to build a service to do that using "googleapis": "^71.0.0"

const {google} = require('googleapis');
const service = google.people({version: 'v1', auth});
service.people.searchDirectoryPeople({
  sources: ['DIRECTORY_SOURCE_TYPE_DOMAIN_PROFILE'],
  readMask: 'photos',
  query: '*'
}, (e,r)=>{
  console.log(e, r);
})

This didn't work. Anyone tried anything similar to gravatar service

https://www.gravatar.com/avatar/${md5(email-address)}

I am looking to create a service to take in one email and get the profile image on the fly or a service for bulk email ids so I can persist them if the above service is too expensive.

Upvotes: 0

Views: 880

Answers (1)

bmcculley
bmcculley

Reputation: 2088

You can retrieve a user photo from the directory api using either the unique user id or their email address.

https://developers.google.com/admin-sdk/directory/v1/guides/manage-users#get_photo

Upvotes: 1

Related Questions