0

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);
    });
  }
  • You don't return from makeCalendarApiCall, so there can't be anything but undefined. You'd also have to chain it with then. The next problem is your globally declared `i`, do let i = 0 instead – baao Jun 19 '18 at 22:03
  • I am trying to understand if my code is Promise or not. On the other hand, sorry but I couldn't understand what you meant by i variable. Thank you. – Ersan Aşkın Jun 21 '18 at 00:24

0 Answers0