Ошибка: модуль Node.js, определенный в файле index.js, должен экспортировать функцию с именем xxxx
Привет, сообщество разработчиков. Я пытаюсь отладить функцию Firebase и пытаюсь использовать несколько учебных пособий, но безуспешно...
Я пытался ( https://medium.com/@mwebler/debugging-firebase-functions-with-vs-code-3afab528bb36) ( https://medium.com/@david_mccoy/build-and-debug-firebase-functions-in-vscode-73efb76166cf)
Моя цель - получить контакты Google.
Функции /index.js
const { google } = require('googleapis');
const oauthUserCredential = require('./oauthUserCredential.json')
const OAuth2 = google.auth.OAuth2
const key = require('./serviceAccountKey.json')
const jwt = new google.auth.JWT(key.client_email, null, key.private_key, 'https://www.googleapis.com/auth/contacts')
exports.getGoogleContacts = functions.https.onCall(async (data, context) => {
const requestingUser = data.requestingUser
console.log('getGoogleContacts-requestingUser', requestingUser)
const oauth2Client = new google.auth.OAuth2(
'client_id',
'client_secret',
'http://localhost:5000/xxx-xxx/us-central1/OAuthCallbackUrl'
);
const contacts = google.people({
version: 'v1',
auth: oauth2Client,
});
console.log('contacts ?', contacts)
(async () => {
const { data: groups } = await contacts.people.get({
resourceName: 'contactGroups',
});
console.log('Contact Groups:\n', groups);
})()
jwt.authorize((err, response) => {
console.log('inside authorize')
if (err) {
console.error(err);
response.end();
return;
}
// Make an authorized request to list contacts.
contacts.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);
});
});
// this is another approach I´ve tried, but it´s also not working
const oAuth2Client = new OAuth2(
oauthUserCredential.web.client_id,
oauthUserCredential.web.client_secret,
oauthUserCredential.web.redirect_uris,
)
oAuth2Client.setCredentials({
refresh_token: oauthUserCredential.refresh_token
})
return new Promise((resolve, reject) => {
console.log('[INSIDE PEOPLE CONNECTIONS]')
contacts.people.connections.list({
auth: oauth2Client //authetication object generated in step-3
}, function (err, response) {
if (err) {
console.log('contacts.people.connections error')
console.log(err)
reject(new Error(err))
} else if (response) {
console.log('contacts.people.connections response')
console.log(response)
resolve(response)
}
});
})
.then(result => { return { found: result } })
.catch(err => { return { error: err } })
})
Я пробовал несколько разных подходов и следовал различным учебным пособиям ( Использование Google People API с облачными функциями для Firebase) ( https://flaviocopes.com/google-api-authentication/) ( https://medium.com/@smccartney09/integrating-firebase-cloud-functions-with-google-calendar-api-9a5ac042e869) ( https://cloud.google.com/community/tutorials/cloud-functions-oauth-gmail)
но ни один из них не показывает ясно, как я мог получить свой список контактов. Я смог использовать код на стороне клиента, следуя этому руководству ( https://labs.magnet.me/nerds/2015/05/11/importing-google-contacts-with-javascript.html), но я думал, что client_id, client_secret и apiKey, представленные на стороне клиента, будут проблемой безопасности...
Я также отправляю учебный запрос, чтобы было очень ясно, как получить список контактов из учетной записи Google с помощью функций Firebase.
0 ответов
Ошибка, которую вы получаете, связана с тем, что облачная функция не может найти функцию с именем xxxx для выполнения, поскольку вы не определили ни одной функции с именем xxxx в файле index.js.
Имя вашей облачной функции для выполнения, согласно сообщению об ошибке, - xxxx, но функция, которую вы вызываете в index.js, - это getGoogleContacts. Убедитесь, что эти имена совпадают, например измените getGoogleContacts на xxxx или измените функцию для выполнения на getGoogleContacts