I have this code
function LoadEmailIdsToCheck() {
fs.readFile(config.googleCredentials, function processClientSecrets(
err,
content
) {
if (err) {
console.log("Error loading client secret file: " + err);
// return;
}
// Authorize a client with the loaded credentials, then call the
// Gmail API.
authorize(JSON.parse(content), getEmails);
});
}
function authorize(credentials, callback) {
var clientSecret = credentials.installed.client_secret;
var clientId = credentials.installed.client_id;
var redirectUrl = credentials.installed.redirect_uris[0];
var OAuth2 = google.auth.OAuth2;
var oauth2Client = new OAuth2(clientId, clientSecret, redirectUrl);
...
}
function getEmails(auth) {
const gmail = google.gmail({ version: "v1", auth });
gmail.users.messages.list(
{
userId: "me"
},
(err, res) => {
if (err) return console.log("The API returned an error!: " + err);
else {
response = res
return response;
}
}
);
}
When I trigger the code with "LoadEmailIdsToCheck()" then I will not get a return of the callback function. If I do a console.log(res) it prints out the needed data but I can't execute a "return res".
So my question is why? And how can I solve this problem?