Existence of an email id in a domain - google-apps-script

How to check a Google app account is present in a domain or not using Google app script (with email id)?
I would like to reset the password of accounts in my domain. Before that i need to check if those accounts exists in my domain or not. So with a given email id, i need to check id this particular email id is present in my domain or not and it should be primary email address.
Please let me know if this is feasible or not.
Thanks

I think you can try to retrieve all users in your domain by following this documentation.
To retrieve all users in the same domain, use the following GET request and include the authorization described in Authorize requests. For readability, this example uses line returns:
GET https://www.googleapis.com/admin/directory/v1/users ?domain=primary domain name&pageToken=token for next results page
&maxResults=max number of results per page
&orderBy=email, givenName, or familyName
&sortOrder=ascending or descending
&query=email, givenName, or familyName:the query's value*
Also check this SO question, if it can help you.

Related

Get drive files stats (views/openings) | Google Drive API

I've been searching the docs but I can't find anything.
The goal is to retrieve different stats from our files. Actually, we can retrieve almost everything we need, except for the document openings and document openings per user.
So here is the question: How can I retrieve document views of a drive document (a G Sheet to be more precise) ? Can I segment it by user ?
Thank you
I understand that your goals are the following one:
You want to retrieve document views
Of a particular document (and you know it's id)
Associated to a specific user
Please correct me if I get it wrong. If those are your goals, then you can use the Admin SDK as pointed out by Rubén in the comments. Now I am going to detail how you can make such a request easily.
You could use the method activities.list() to get a list with what you want. You only have to populate these four parameters:
Parameter
Value
Description
userKey
The user's email
Determine the user
applicationName
drive
Identifies the Google service
eventName
view
Designate the type of activity
filters
doc_id=={MY DOCUMENT ID HERE}
Filters by the document
That configuration will provide you with your desired data. Leave a comment below if you need help creating that request in your own environment.

Get User's first and last name via Google API

Currently I am developing a Chrome-GMAIL extension which requires me to get the logged in user's first and last names. For experimentation, I have used the following goggle API (userinfo) and have successfully obtained the names I wanted:
https://www.googleapis.com/auth/userinfo.profile
However, using the userinfo APIs will cause a change in the OAuth2 scopes in my manifest. This change will in turn cause a permission-prompt to my existing users (if a domain wide delegation is not setup in place). Point being the idea of having more prompts in front of my user, or additional oauth scope is not really something I desire.
Currently our extensions use the following OAuth scopes and API :
Chrome's Identity API
Chrome's Storage API
GMAIL.modify
GMAIL.send
My question is, is it possible to get the first and last names using an API that is defined/allowed/provided for by any of the above scopes/permissions I listed? or is userinfo the only way to go?
Thank you very much.
Profile data like first name and last name is private data. You are corect that some Google apis give you access to some data that would normally require an extra scope. For email normally you would need to to request the email scope to get this back however the Gmail api does have an endpoint getprofile which will return the current users email address without you requesting the email scope.
However i am not aware of any apis that will give you access to the users first and last name without you requesting the profile or user.profile scope.
If you do decide to add the scope, I do recommend going though the people api rather then the userinfo endpoint as the data returned by the user info endpoint is not guaranteed to always return the name.

Classroom.profiles.get returns 'User does not have permission'

I am trying to write a simple function to get all the students names and email addresses for a given class. The students have a mixture of mydomain.ac.uk and gmail.com. The students that have a mydomain.ac.uk address all return without problem, but if the student has a gmail account, I get the error 'The caller does not have permission'.
If I view the People tab of the course using the same superAdmin account that runs the code, I can see all of the students names and can email them. How do I get my code to return the userProfile of these gmail account users?
var sEmail = Classroom.UserProfiles.get({'userId' : '111294713083730379429'}).emailAddress
If I can see this information in the Classroom, why can't I access the same information in my code?
From the question
If I can see this information in the Classroom, why can't I access the same information in my code?
Only Google can answer why. Please bear in mind that the user profile data for #gmail.com is stored on an external domain, gmail.com.
I suggest you to checkout the Google Classroom Issue Tracker if there is already an issue about this "feature".

Getting the correct Google client ID for Chrome users with multiple accounts

I'm trying to get the Google Client Id (found under https://plus.google.com/me) of a user corresponding to the account he's currently connected with.
Explanation: when connecting with your gmail account on Chrome, the result of the code given here (https://developers.google.com/+/web/people/) gives the user's client ID that I need to use the Google Payment API.
The problem is if the user has multiple accounts connected on Chrome.
Example: Our user has an email account for work (WEmail) and a personal email account (PEmail). He first connects to chrome using his WEmail. Then adds his PEmail to the list of Chrome connected accounts. Then our user wishes to make a payment on an extension he has installed, with his PEmail.
The issue here is that to process such a payment you need the google client ID of that user, and when you fetch it, you will get the one of the first connected account (WEmail) and not the one of the current used account (PEmail). Which makes it impossible to process the payment since you might not be serving the right account.
Is there any way to get all the currently used ids of a user or jsut the currently used id?
If not, are there plans to integrate such a solution in the short term?
Thanks for your help.

Google Contacts API's and scope?

Currently i'm trying to retrieve all of a users contact information as well as retrieve their unique User ID.
Our app needs to utilise a users google contacts and the user will sign in using google. Thus we require some way of identifying each unique user (most likely a unique user id provided by google)
Is this possible only using the google contacts API.
The initial call I make to retrieve an access token is:
"https://accounts.google.com/o/oauth2/auth?client_id=51672309258-94cnvnrkrverd72neakom9d3siscda5o.apps.googleusercontent.com&redirect_uri=http://localhost/lunch/oauth.php&scope=https://www.google.com/m8/feeds/&response_type=code"
However I do not believe the access token returned from this call has any information for user ID and, also, does not provide the permissions to retrieve User ID from the Google+ Api.
Is there anyway that one can obtain a unique user ID from the google contacts API? There are examples of obtaining a user id of the users contacts but I need to obtain the actual users ID (i.e. the user whose contacts I am obtaining)?
Does this require another scope or can this also be accomplished by using the contacts API?
You can identify a user by his/her email address, which is unique AFAIK. When you issue requests to google contacts api you get a field in the xml which is called Id, that is the user's email address.
For example you could ask for all contacts and you would get an xml like this .The Id field is what you want, and depending on the programming language, lib , etc you are using you can get it with your existing permissions. For example in C# and gdata you would do something like this(googleCredentials is supposed to be your object):
var cr = new ContactsRequest(settings);
var feed = cr.GetGroups();
googleCredentials.Email = feed.AtomFeed.Id.Uri.Content;
Note: The special userEmail value default can be used to refer to the
authenticated user.
from the documentation documentation. You may try the keyword default as userEmail.