Accessing Gmail contact groups through existing Gmail OAuth without separate Contacts API authentication

I’m working on an application that already uses Gmail OAuth for email functionality. Now I need to retrieve the user’s contact groups, but I want to avoid making users go through another authentication process for the Contacts API.

Is it possible to fetch contact group information using just the Gmail OAuth token I already have? I’ve seen examples using the dedicated Google Contacts API, but that requires additional permissions and authentication steps.

I’m hoping there’s a way to access this data through the Gmail API endpoints or by extending my current OAuth scope without requiring users to authorize a completely separate API. Has anyone found a solution for this scenario?

Any guidance on the proper approach or API endpoints would be really helpful.

To access contact groups, you’ll have to use the Google Contacts API, as the Gmail API itself doesn’t expose this functionality directly. However, if you configure your OAuth scopes properly, you can avoid requiring users to authenticate separately. Simply include ‘https://www.googleapis.com/auth/contacts.readonly’ in your OAuth scopes during the initial setup, which allows your existing token to work across both APIs.

For users already using Gmail-only tokens, implement scope expansion properly by making use of incremental authorization. This way, when you notice that the Contacts permissions are missing, you can prompt for the necessary permissions without making users go through the complete re-authentication process. Utilizing the ‘include_granted_scopes’ can help streamline this experience. You’ll interact with the endpoints ‘/people/contactGroups’ to list contact groups and ‘/people/contactGroups/{resourceName}/members’ to fetch members of a specific group.

You’re correct in trying to streamline the authentication process. However, Gmail API and Google Contacts API are distinct services, which means you can’t retrieve contact groups through the Gmail API. You should adjust your OAuth setup to include both scopes right from the start. Specifically, when setting up your OAuth credentials, ensure that both https://www.googleapis.com/auth/gmail.readonly and https://www.googleapis.com/auth/contacts.readonly are included in your scope parameters. This will allow you to use a single token for both APIs without requiring a second authentication.

If users already possess tokens for Gmail only, you can still manage scope expansion via incremental authorization. The OAuth library from Google supports requests for additional permissions without compromising existing ones. Make sure to set include_granted_scopes to true when seeking the expanded permissions. Once you have the necessary scopes, utilize the People API endpoints to access contact group data, as it remains unavailable through Gmail’s endpoints.

yeah, this trips people up all the time. gmail API doesn’t handle contact groups - that’s what the contacts API is for. but here’s the thing: you don’t need separate auth if you’re smart about it. just throw the contacts scope into your initial oauth request with your gmail scopes and you’re golden - one token does everything. already got users with gmail-only tokens? no biggie, just use incremental auth to add the new permissions.