Google应用程序凭证Python(Jupyter笔记本)

发布于 2025-02-03 14:46:17 字数 709 浏览 4 评论 0 原文

正如Python和Jupyter Notebook所指示的,我正在尝试开始使用Google Analytics API 4。我遵循指示并进入步骤3。配置身份验证

,然后他们写下您需要设置google_application_credentials =“ [path]我将此文件下载到我的计算机并将其添加到项目文件夹中,但是我无法使用服务帐户进行验证。

在github上,他们写 https://github.com/googlapis/googleapis/googleapis/python-analytics-dataa#安装您需要使用虚拟环境吗?是吗?没有它会起作用吗?

我正在使用服务元,而不是OAuth 2.0

I'm trying to start using Google Analytics API 4 as instructed with Python and Jupyter Notebook. I follow the instructions https://developers.google.com/analytics/devguides/reporting/data/v1/quickstart-client-libraries and get to Step 3. Configure authentication

And then they write that you need to set GOOGLE_APPLICATION_CREDENTIALS="[PATH]" I downloaded this file to my computer and added it to the project folder, but I can't get verified using the service account.

On github they write https://github.com/googleapis/python-analytics-data#installation that you need to use a virtual environment? Is it so? Will it work without it?

I am using service-account, not oauth 2.0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北凤男飞 2025-02-10 14:46:17

要清楚Google_application_credentials是虚拟环境变量。许多Google客户端库都使用此变量来加载任何API的凭据。我已经重复了这个问题,因为它显示了许多设置它的方法。

因为您似乎仍然不确定。这是一些附加信息。

如文档中所述。

提供服务帐户凭据的一种简单方法是设置 google_application_credentials环境变量,API客户端将使用此变量的值来查找服务帐户键JSON文件。

您需要将计算机上的env var设置为服务帐户密钥文件的路径。

有许多有关如何做到这一点的示例。

To be clear GOOGLE_APPLICATION_CREDENTIALS is a virtual environmental variable. This variable is used by many of the google client libraries to load the credentials for any of the APIs. The question i have duplicated this as shows a number of ways to set it.

As you seem to still be a little unsure. Here is some additinal information.

As stated in the docs.

An easy way to provide service account credentials is by setting the GOOGLE_APPLICATION_CREDENTIALS environment variable, the API client will use the value of this variable to find the service account key JSON file.

You need to set an env var on your machine to the path of the service account key file.

enter image description here

There are a number of examples of how to do that.

心是晴朗的。 2025-02-10 14:46:17

我做到了。我会告诉您初学者的结果:

  • 单击蓝色按钮启用Google Analytics Data API V1,创建一个项目在Google Cloud中创建了一个服务帐户,并激活了Google Analytics(分析)API。下载JSON文件

  • 之后,您需要在GA4 Resource

    中添加一个服务帐户

  • 中添加一个服务帐户,然后您需要根据此处的方法进行身份验证“ rel =“ nofollow noreferrer”> https://cloud.google.com/docs/authentication/authentication/production#setting_the_environment_variew
    这需要手动通过凭据。使用文章中的代码,指示计算机上JSON文件的路径

使用文章中的代码,在尝试身份验证服务帐户时, ,403 get storage.googleapis.com/storage/v1/其他。 -data-api-1654114095791.iam.gserviceaccount.com没有storage.buckets.list访问Google Cloud Project。

为此,您需要转到IAM并为所有者或存储管理服务帐户创建新角色。之后,Google_application_credentials找到,您可以开始安装数据API库

I did. I'll tell you how it turns out for beginners:

https://developers.google.com/analytics/devguides/reporting/data/v1/quickstart-client-libraries

  • Click on the blue button Enable the Google Analytics Data API v1, a project is created, a service account is created in Google Cloud and the Google Analytics API is activated. Download JSON file

  • After that, you need to add a service account in the GA4 resource

  • Then you need to authenticate according to the method from here https://cloud.google.com/docs/authentication/production#setting_the_environment_variable
    This requires Passing credentials manually. Using the code in the article, the path to the json file on the computer is indicated

When trying to authenticate a service account, 403 GET storage.googleapis.com/storage/v1/… will be issued: starting-account-smhpwtovr5jj @test-data-api-1654114095791.iam.gserviceaccount.com does not have storage.buckets.list access to the Google Cloud project.

To do this, you need to go to IAM and create a new role for the Owner or Storage Admin service account. After that, GOOGLE_APPLICATION_CREDENTIALS finds and you can start installing the Data API library

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文