Being able to access Google user information efficiently is critical for creating responsive user interfaces and automating tasks like sending emails to multiple users within a domain. To meet these requirements, we have introduced a set of features to get specific user information and to retrieve all domain profiles and contacts.
Account connection
Before getting user information, we need to create an OAuth 2.0 connection object:
var $oAuth2:=cs.NetKit.OAuth2Provider.new($credentials)
var $google:=cs.NetKit.Google.new($oAuth2)
Note that multiple scopes may be required to access the user’s information:
- https://www.googleapis.com/auth/contacts
- https://www.googleapis.com/auth/contacts.other.readonly
- https://www.googleapis.com/auth/contacts.readonly
- https://www.googleapis.com/auth/directory.readonly
- https://www.googleapis.com/auth/user.addresses.read
- https://www.googleapis.com/auth/user.birthday.read
- https://www.googleapis.com/auth/user.emails.read
- https://www.googleapis.com/auth/user.gender.read
- https://www.googleapis.com/auth/user.organization.read
- https://www.googleapis.com/auth/user.phonenumbers.read
- https://www.googleapis.com/auth/userinfo.email
- https://www.googleapis.com/auth/userinfo.profile
Fetch Current User Details
The ability to pull information about the currently authenticated user has been added: Google.user.getCurrent(). By default, this returns key details like the user’s name and email address but can be extended to include other attributes such as phone numbers, birthdays, and more.
var $currentUser :=$google.user.getCurrent()
Retrieve All Domain Profiles and Contacts
The Google.user.list() command allows developers to access directory profiles or domain contacts. It includes options for filtering and paginating results to suit different application needs.
var $userList :=$google.user.list()
Get Specific User Information
The Google.user.get() command provides information about a specific person by using their resource name. Developers can specify which data fields to retrieve using a field mask, allowing for efficient data handling.
var $user :=$google.user.get($userList.users[0].resourceName)
Conclusion
These new features empower 4D developers with the tools needed to retrieve Google user information. Whether you’re working on enhancing the user interface or automating emails, having easy access to user data is key to building better applications.