简体   繁体   English

从 Web 应用程序登录到 Stackdriver

[英]Logging to Stackdriver from a web application

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?我想从网络应用程序向 Google Stackdriver 记录一条信息消息,而无需用户登录。这可能吗? I am using gapi from Google.我正在使用谷歌的gapi。

gapi.load('client:auth', start); gapi.load('client:auth', start);

then => gapi.client.init({ apiKey, discoveryDocs, client_id, scope});然后 => gapi.client.init({ apiKey, discoveryDocs, client_id, scope});

then => gapi.auth2.authorize(...)然后 => gapi.auth2.authorize(...)

then => gapi.client.logging.entries.write(...);然后 => 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.对于 Google Sign In 对于网站,必须对Google 帐户进行身份验证,这是因为在使用 API 之前,用户必须在 Google 登录屏幕上授权使用某些范围。

To write logs from an application (with backend) to a stackdriver service is by creating a service account and using stackdriver logging package要将日志从应用程序(带有后端)写入 stackdriver 服务是通过创建服务帐户并使用stackdriver 日志记录包

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.在同一指南中还解释了如何在 node.JS 代码和其他编程语言中使用包和调用凭证。

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下载服务帐户凭据后,需要使用此命令将 json 文件的路径保存在“GOOGLE_APPLICATION_CREDENTIALS”环境变量中

export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/[FILE_NAME].json"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM