正如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
发布评论
评论(2)
要清楚Google_application_credentials是
虚拟环境变量
。许多Google客户端库都使用此变量来加载任何API的凭据。我已经重复了这个问题,因为它显示了许多设置它的方法。因为您似乎仍然不确定。这是一些附加信息。
如文档中所述。
您需要将计算机上的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.
You need to set an env var on your machine to the path of the service account key file.
There are a number of examples of how to do that.
我做到了。我会告诉您初学者的结果:
单击蓝色按钮启用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