/**
* Log the details of all contacts that have email address and birthday information.
*/
function getNamesEmailAddressesBirthdaysData() {
let response; // Variable to store the response from the API call
const options = {
// pageSize: 10, // Number of contacts to fetch per API call
personFields: 'names,emailAddresses,birthdays' // Fields to retrieve for each contact
};
const callback = People.People.Connections.list; // Reference to the API method for listing contacts
do {
response = callback('people/me', options); // Make an API call to get the list of connections
response.connections.forEach(connection => { // Iterate over each connection in the response
if (connection.emailAddresses && connection.birthdays) { // Check if the connection has both email addresses and birthdays
const name = connection.names ? connection.names[0].displayName : 'No Name'; // Get the display name or set to 'No Name' if not available
const email = connection.emailAddresses[0].value; // Get the first email address
const birthday = connection.birthdays[0].date; // Get the birthday date object
const formattedBirthday = `${birthday.year}-${birthday.month}-${birthday.day}`; // Format the birthday as YYYY-MM-DD
console.log(`Name: ${name}, Email: ${email}, Birthday: ${formattedBirthday}`); // Log the contact's details
}
});
options.pageToken = response.nextPageToken; // Update the pageToken to get the next set of results
} while (options.pageToken); // Continue looping until there are no more pages of results
}