Connecting Google Drive comment authors to their email addresses

I’m trying to figure out how to link comments on Google Drive files to the email addresses of the people who made them. The problem is that the author info in a Comment object doesn’t have an email or a unique ID.

I thought about matching display names with users from about.get, but that’s not great because names can be the same for different people. The profile pictures don’t work either because the links are different in comments and about.get, even for the same person.

It’s really weird that we can’t easily connect comments to email addresses. Does anyone know a way around this? I feel like I’m missing something obvious. Has anyone else run into this issue and found a solution?

Here’s a quick example of what I’ve tried:

def get_comment_author_email(comment):
    author = comment['author']
    display_name = author['displayName']
    
    # This doesn't work reliably
    user = find_user_by_display_name(display_name)
    
    if user:
        return user['emailAddress']
    else:
        return None

# We need a better way to do this!

Any ideas would be super helpful. Thanks!

yo, i feel ur pain. tried this myself n got nowhere. one trick i stumbled on: use the drive activity api instead. it gives more deets on who did what, including emails sometimes. might help connect the dots. worth a shot, right? good luck!

I’ve encountered this issue before, and it’s indeed frustrating. Unfortunately, there’s no straightforward way to directly link comment authors to their email addresses due to privacy considerations.

One workaround I’ve used is to create a custom property for each file, storing a mapping of display names to email addresses. This requires some setup:

When sharing the file, capture the user’s email and display name. Store this information in the file’s custom properties. When retrieving comments, use the custom property to look up the email.

It’s not perfect, as it requires additional overhead and doesn’t work retroactively, but it’s the most reliable method I’ve found. Google’s API limitations in this area are intentional to protect user privacy, so we often need to implement our own tracking systems.

I’ve wrestled with this exact problem in a project I worked on last year. It’s a real pain point in the Drive API. One unconventional approach that worked for me was leveraging the Google Admin SDK, if you have admin access to your organization’s Google Workspace.

Here’s the gist: Use the Admin SDK to pull a list of all users in your organization. Then, create a lookup table mapping display names to email addresses. When you get comments, cross-reference the author’s display name against this table.

It’s not foolproof - you might still have name collisions - but it’s more reliable than trying to match names on the fly. Plus, you can periodically update your lookup table to keep it current.

Just be aware this method only works for comments from users within your organization. External collaborators will still be a challenge. In those cases, you might need to fall back to manual mapping or user prompts.