get first and last name from e-mail address in Enterprise G-Suite - google-apps-script

I am trying to find a user's name from their e-mail address. I thought I could use People.People.get as mentioned here but that requires knowing the user's account ID.
How can I get information about the user if I only know their e-mail?
And I don't think I can use the Directory API cause I don't have admin access.

You can use Admin Directory API to get user's details. While making the URL call, you need to specify a parameter in the request body which is (viewType:"domain_public"), so you will get the basic details of the user in your domain without having admin rights.
Reference Link : https://developers.google.com/admin-sdk/directory/v1/reference/users/get

I don't think you can do it without Admin Rights, on the link you mentioned you need the AccountId which can only be retrieved by having Admin Rights and Access to the Directory API (https://developers.google.com/admin-sdk/directory/v1/reference/users/get) which you mentioned tyou don't have access to.
You could ask to your Administrator to get an Admin Role https://support.google.com/a/answer/172176?hl=en to use the Admin SDK for complete your task, it will be easier for you. The other way I don't know how the contact sharing is setup in your organization because you should be able to check the information of the contact when sending an email or adding it to your contact list.
I hope this information can be of help. Greetings.

Related

How can I access a user's email with my chatbot?

I'm making a Hangouts chatbot for my company, and one of the things we need to do is retrieve a user's email address. The API guide says that chatbot should be able to access this information without any additional permissions or API's, but I can't find out how to do it. I can get the user object from the event, but from that I can only get displayName.
Thanks
It turns out you can access an email with event.user.email
Doesn't say that anywhere in the documentation but whatever...

Admin access to Domain User's Gmail?

I'm currently writing an auditing script that is focusing on users' gmails and need access to their message lists. I have admin access and scopes for the AdminSDK, the script will be executed by the admin.
I'm wondering how exactly to do this? I have my domain's userlist via Directory, but I can't use GmailApp with a specific user, only the current user(admin). I was also thinking about assigning a timed Trigger to each of the users and using GmailApp locally, but I can't figure out how to do that either(I don't think this is possible).
One idea that I'm working on is pinging the Gmail API using the admin's credentials via URLFetchApp, but can I get my domain's users information with this method?
What are your thoughts? Any guidance will be appreciated.
I'm currently using GAS on a service account.
While using service account, you can impersonate users in your domain and perform actions on their behalf. For this you will need to perform domain wide delegation of authority in your domain.
Here you can find documentation about domain wide delegation.
Here you can see an example, I know is on Drive but the principle is the same.
Hope this helps.

user email in About service

I need to get the user email when I get document permissions. I have seen this problem here
value attribute for Permissions Resource not populated in responses
but in about service does not appear my email. I need it because I have a service account and my application need know the user email. I want to avoid call to profile service.
Is this possible? from where I can get the user email?
Thanks.
As you rightly say, you will have to make a call to the profile service. In some ways it is better like this, because it separates the concerns of the Drive API and the Profile API, and can use specific scoping to let the user know exactly what they are authorizing your app to do.

about service accounts and unregistered users

I have a web app in php mysql, I want to use one google drive account for my app.
Can I use my app's accounts instead of google users for privilages.
I read in SDK I can use service account to login without promting user, but I don't know how to share or give permissions files for custom users.
In api reference I found this:
"The user is not necessarily yet a Google user (e.g. if a file or folder is shared with an email address that does not yet have an associated Google account). Example: 1111459233037698895607".
How a custom user in my app should get a token for own privilages.
I am not exactly sure what you want to achieve here, but if you want to use your own permission system, you can't. You can, however, apply read/write/owner permissions to files to mirror your own permissions.
If I have totally got the wrong idea, please explain.

Facebook OAuth getting only email, possible?

I'm busy to enable login stuff via facebook oauth on my website, but the only thing I want to get is the email of the user.
I saw in dev docs the 'scope=email' but, it seem's mandatory for the user to allow access to anything about him.
is there's a way to ask him to grant access only on his email ?
No. The bare minimum that your app will request from the user is his Basic Information, followed by your extended permissions (in your case, his email address).
nope. email is a so called extended permission. so you have to get the basic set of data of the user. (like: name, fbid, gender, locale).