I would like to log an info message to Google Stackdriver from a web app without the user having to sign in. Is it possible? I am using gapi from Google.
gapi.load('client:auth', start);
then => gapi.client.init({ apiKey, discoveryDocs, client_id, scope});
then => gapi.auth2.authorize(...)
then => gapi.client.logging.entries.write(...);
=> PERMISSION DENIED**
Everything I try requires the user to sign in. Any idea?
For Google Sign In For websites, is mandatory authenticate a google account, this is because the users must authorize the use of some scopes on the Google Login Screen before use the API.
To write logs from an application (with backend) to a stackdriver service is by creating a service account and using stackdriver logging package
You could find all information and steps to create and download your service account credentials in this guide.
Also in the same guide are explained how to use the package and call the credential in a node.JS code and in other programming languages.
When you have downloaded your service account credentials is necessary to save the path of the json file in the "GOOGLE_APPLICATION_CREDENTIALS" ENV variable using this command
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/[FILE_NAME].json"
Thank you answering! Would your suggestion with a node.js logging package also work in a Angular 8 web app hosted at google firebase?
if your backend is node.js this will work without defining any environment variables since applications in firebase/GCP already have the variables configured
The backend isn't built with node.js. I wonder if I can use the package anyway.
I'm not sure if it is possible, according the docs stackdriver only works with some backend languages such as Node.JS, php, python, etc.. cloud.google.com/logging/docs/setup