I’m developing a Gmail gadget and need to get the user’s company or Apps account domain name. This info would help me show different content to users from the same domain.
Is it possible to access this data? I know Gmail sidebar gadgets can’t usually get user info without OAuth.
I’ve seen examples of getting user contacts with OAuth, but I’m not sure which feed to use for the domain info. Can anyone point me in the right direction?
Here’s a simple code snippet to illustrate what I’m trying to do:
function getDomainInfo() {
// This is where I need help
var domain = getUserDomain();
if (domain === 'companyA.com') {
showCompanyAContent();
} else if (domain === 'companyB.com') {
showCompanyBContent();
} else {
showDefaultContent();
}
}
Any ideas on how to implement the getUserDomain() function? Or is there a better way to approach this?
Hey ClimbingLion, i’ve been there too. sadly, getting the domain directly ain’t possible. But here’s a trick - use OAuth to grab the user’s email, then extract the domain part. It’s not perfect, but it works. Just remember to handle personal gmail accounts differently. good luck with ur gadget!
From my experience working with Gmail gadgets, directly accessing the domain information is not feasible due to security constraints. However, I’ve found a workaround that might suit your needs. You can utilize the Gmail API with OAuth2 to fetch the user’s email address, then extract the domain portion. Here’s a basic approach:
- Set up OAuth2 for your gadget
- Use the Gmail API to retrieve the user’s profile
- Parse the email address to get the domain
Keep in mind this method isn’t foolproof. You’ll need to handle cases where the user has a personal Gmail account or when authorization fails. Also, ensure you’re compliant with Google’s terms of service and privacy policies when implementing this solution.
I’ve encountered a similar challenge in my work with Gmail gadgets. Retrieving the Google Apps domain directly is not straightforward because of privacy restrictions. In my experience, a reliable workaround has been to fetch the user’s email address using the Gmail API with proper OAuth2 permissions and then parse the domain from that address. This method, while not ideal, has worked for me when careful handling of permissions and potential issues like personal Gmail accounts is in place.
It’s important to consider that this approach may require additional steps to manage cases where no email data is available, but it has proven effective in many real-world scenarios.