Google API-Javascript客户端-函数返回

时间:2018-06-19 22:00:28

标签: javascript function-calls google-calendar-api google-people

我为Google People和Google Calendar API提供2个功能。 我正在从带参数的makePeopleApiCall调用makeCalendarApiCall函数。

函数正在运行,但是我无法将makeCalendarApiCall的响应返回给makePeopleApiCall函数。

有什么主意吗?

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 个答案:

没有答案