Unable to get firebase function logs of node.js in Google Cloud Logs Explorer
I have successfully deployed my node.js code to smarthome by Google Actions.
I have added smarthome devices to GoogleHome App and when I operate device operations I didn't get any function logs in Google Cloud logs page.
Here is the some part of my code that I used for smarthome.
Why console.log is not happening?
/**
* Copyright 2018 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
const { onRequest } = require("firebase-functions/v2/https");
const { onValueWritten } = require("firebase-functions/v2/database");
const { smarthome } = require("actions-on-google");
const { google } = require("googleapis");
const { logger } = require("firebase-functions");
const admin = require("firebase-admin");
const axios = require("axios");
const fetch = require("node-fetch");
const util = require("util");
const serviceAccount = require("");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: ""
});
//admin.initializeApp();
const firebaseRef = admin.database().ref('/');
const auth = new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/homegraph'],
});
const homegraph = google.homegraph({
version: 'v1',
auth: auth,
});
// Hardcoded user ID
const USER_ID = '102';
exports.login = onRequest((req, res) => {
if (req.method === 'GET') {
logger.log('Starting of GET ');
logger.log('Requesting login page');
res.send(`
`);
logger.log('%s',req.query.responseurl);
} else if (req.method === 'POST') {
const responseurl = decodeURIComponent(req.body.responseurl);
logger.log('__POST__START_%s',req.body.responseurl);
logger.log(`Redirect to ${responseurl}`);
return res.redirect(responseurl);
} else {
// Unsupported method
res.send(405, 'Method Not Allowed');
}
});
exports.fakeauth = onRequest((request, response) => {
const responseurl = util.format('%s?code=%s&state=%s',
decodeURIComponent(request.query.redirect_uri), 'xxxxxx',
request.query.state);
logger.log(`Set redirect as ${responseurl}`);
logger.log('Ending of FAKEAUTH');
return response.redirect(
`/login?responseurl=${encodeURIComponent(responseurl)}`);
});
exports.faketoken = onRequest((request, response) => {
const grantType = request.query.grant_type ?
request.query.grant_type : request.body.grant_type;
const secondsInDay = 86400; // 60 * 60 * 24
const HTTP_STATUS_OK = 200;
logger.log(`Grant type ${grantType}`);
let obj;
if (grantType === 'authorization_code') {
obj = {
token_type: 'bearer',
access_token: '123access',
refresh_token: '123refresh',
expires_in: secondsInDay,
};
} else if (grantType === 'refresh_token') {
obj = {
token_type: 'bearer',
access_token: '123access',
expires_in: secondsInDay,
};
}
response.status(HTTP_STATUS_OK)
.json(obj);
});
const app = smarthome();
app.onSync(async (body, headers) => {
const authorizationHeader = headers.authorization;
const accessToken = authorizationHeader.split(' ')[1];
console.log('----onSync accessToken', accessToken);
let medhaResponse;
});