我正在使用Firebase的Cloud Functions来从Google People API中获取联系人列表,但是只能得到一个空对象作为响应。有什么想法吗?以下是Cloud Functions代码:
var functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
var google = require('googleapis');
var people = google.people('v1');
exports.contacts = functions.https.onRequest((request, response) => {
admin.database().ref('/settings/contacts/credentials/serviceAccount').once("value", function(data) {
var authClient = new google.auth.JWT(
data.child('clientEmail').val(),
null,
data.child('privateKey').val(),
['https://www.googleapis.com/auth/contacts'],
null
);
authClient.authorize(function (err, tokens) {
if (err) {
console.error(err);
response.end();
return;
}
// Make an authorized request to list contacts.
people.people.connections.list({auth: authClient, resourceName: 'people/me'}, function(err, resp) {
if (err) {
console.error(err);
response.end();
return;
}
console.log("Success");
console.log(resp);
response.send(resp);
});
});
});
});
在Firebase控制台日志中,成功消息与空的JSON对象一起打印出来。似乎已经成功授权,但不太确定发生了什么。非常感谢您的帮助。