Google APIs - Javascript Client - function return

18 views Asked by At

I have 2 functions for Google People and Google Calendar APIs. I am calling makeCalendarApiCall function from makePeopleApiCall with an argument.

Functions are working but I can't return makeCalendarApiCall's response to the makePeopleApiCall function.

Any idea?

function makeCalendarApiCall (GID){
        gapi.client.calendar.events.list({
            'calendarId': 'primary',
            'privateExtendedProperty' : 'GcontactID = ' + GID 
            })
        .then(function(response){
            console.log(response.result.items); //LOGS THE OBJECT
            return response.result.items; 
        });

};


function makePeopleApiCall() {
    // Make an API call to the People API, and print the user's given name.
    gapi.client.people.people.connections.list({
      'resourceName': 'people/me',
      'personFields': 'names',
      'sortOrder' : 'FIRST_NAME_ASCENDING',
      'pageSize' : 1000
    }).then(function(response) {
     for(i=0; i<3; i++){
      if(response.result.connections[i].names){
console.log(makeCalendarApiCall(response.result.connections[i].names[0].metadata.source.id)); //THIS LOGS UNDEFINED
      }
     }
    }, function(reason) {
      console.log('Error: ' + reason.result.error.message);
    });
  }
0

There are 0 answers