Warm tip: This article is reproduced from stackoverflow.com, please click
google-cloud-logging google-signin logging oauth-2.0

Logging to Stackdriver from a web application

发布于 2020-04-19 09:29:00

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?

Questioner
DStone
Viewed
53
JorgeHDZ 2020-02-13 08:06

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"