Posts

Showing posts with the label firebase functions

Grab Google Analytics Data in remote account from Firebase Functions

Image
Although Google analytics Login is isolated from other Google services, you can easily access the analytics data from another service.  I am going to demonstrate how to retrieve google analytics data from firebase functions. You need to use googleAPI node package as an assistant. In coding, you have to use  JWT authentication in order to avoid async await issue in Google Cloud functions. Currently stable version of cloud functions is Nodejs 6. You have to download the service-account.json from Firebase or google cloud. In firebase, it is located at the following link. You have to generate a new private key. https://console.firebase.google.com/u/0/project/<project-id>/settings/serviceaccounts/adminsdk Make sure it contains the client email. That email need to be added in Analytics >>admin >> User Management Section as a user. https://analytics.google.com/analytics/web/ The code block in the batchGet fuctions will execute in firebase functions no

Google Cloud Scheduler using Firebase Functions

Image
Google recently released a beta version of Google Cloud Scheduler . It makes much easier to schedule a task in firebase. https://cloud.google.com/scheduler/docs/tut-pub-sub You should enable APIs before proceed. Sorry, you have to have a billable account for continue. https://cloud.google.com/scheduler/docs/quickstart gcloud config list  gcloud config set project <projectname> gcloud components update gcloud pubsub topics create cron-job . *** name of the pub sub cron-job gcloud pubsub subscriptions create cron-sub --topic cron-job After creating that , you have to go to shecdular https://console.cloud.google.com/cloudscheduler Select the project and create a scheduled task . In target select pub sub and give the topic as the same name given in pub-sub generation above (cron-job ). After creating the job you can define the code to execute in the firebase functions. The code in the firebases function will be like below for pub sub job name "cr

Firebase Storage ApiError: Forbidden #299 ... ApiError: Forbidden at new util

Image
When, I want to utise firebstore for the frist time in the google cloud functions,  the main problem I had to face it the integration issue raise as follows.  The google firebase and the google cloud storage eveloved seperately and in order to use the clould storage in firebase functions, the special autherntication need to be grantted even you are using firebase admin sdk. ApiError: Forbidden at new util.ApiError (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:107:10) at Object.parseHttpRespMessage (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:149:33) I implemeted the firebase admin sdk as follows. const firebaseAdmin = require("firebase-admin"); firebaseAdmin.initializeApp(functions.config().firebase); And firebase cloud bucket implemented  as follows . const storageRoot = firebaseAdmin.storage().bucket() Google document also indicate authentication req