Reputation: 21
I'm trying to use the People API with Google Apps Script. The objective is to retrieve the info of a directory and then write it in a Google Spreadsheet sheet. The directory contains the information of 330 people. The first problem is that when I use the code (see below), it only retrieves the info of 85 people; every time I've runned it the result has been the same.
The second problem problem is that I can't get the names, nicknames or anyother information about the people in the directory. I can only get emails, phone numbers and ID's, so I would like to know if I'm missing something or I have to trya another method from the GAS People API.
Here's the code. Note that even if I write "names" or "nicknames" in the readmask, it doesn't return that info:
function obtenerDirectorio2() {
var directorio = People.People.listDirectoryPeople({
readMask: 'names,emailAddresses',
sources: 'DIRECTORY_SOURCE_TYPE_DOMAIN_PROFILE',
mergeSources: 'DIRECTORY_MERGE_SOURCE_TYPE_CONTACT'
});
let objeto = JSON.stringify(directorio, null, 2);
let objeto2 = JSON.parse(objeto);
for(let i = 0; i < objeto2.people.length;i++){
Logger.log(correo = objeto2.people[i]);
}
}
Upvotes: 1
Views: 324
Reputation: 1
This API method doesn't work correctly at the moment. There is an issue on Google's tracker for this bug.
Here's a link: people.listDirectoryPeople (or searchDirectoryPeople) response doesn't include names
In the last comment they promise fixing it in Q3 of 2023.
The solution, as a temporal workaround until Google fixes People API
, is to use different API to fetch directory users with names, which is part of the Admin SDK API
, the Directory API
.
Don't let Admin
in the name confuse you, it doesn't require you to be an admin in the org to use its methods to retrieve non-restricted data.
This is the method you need to use: users.list
.
To use it, you will need to add this OAuth scope: https://www.googleapis.com/auth/admin.directory.user.readonly
.
Be sure to:
viewType
parameter to domain_public
, otherwise you'll need admin access to fetch restricted datacustomer
parameter to my_customer
alias to represent your account's customerIdUpvotes: 0