Google Analytics(分析)V4客户端访问我们的应用
我们在PHP中有一个Web应用程序,对于我们的客户,我们已经准备好连接到Google Analytics(分析)UA。我使用“ google/apiclient”:“^2.0”,它可以使用我们的客户在管理中单击按钮,然后运行一个遵循代码:
$this->client = new Google_Client();
$this->client->setApplicationName("xxxx");
$this->client->setClientId("xxxx");
$this->client->setClientSecret("xxxx");
$this->client->setScopes(array("https://www.googleapis.com/auth/analytics.readonly"));
$this->client->setRedirectUri("xxxx");
$this->client->setAccessType('offline');
$this->client->setApprovalPrompt("force");
我从 https://console.cloud.google.com/ - > OAuth 2.0客户端ID
然后将客户端重定向到Google登录,并允许在我们的应用程序的GA数据中加速。然后将代码重新定向,生成访问令牌。有了这个令牌,我可以获取他的GA UA数据,并将其显示给我们管理中的图表。它的工作原理,但是现在我得到了GA UA将会结束的信息,我需要为UA V4创建相同的程序。但是在给GA V4的文档中,我发现的内容: https://develoveler.google.google。 com/ananalytics/devguides/reporting/data/v1 不是信息如何为我们的客户处理它。只有授权过度服务帐户,我必须履行自己的凭据。凭证。也就是说,要通过OAuth 2.0客户端ID将其重定向到Google,并允许访问我们的应用程序以读取其数据。有可能吗?
谢谢您的帮助,很抱歉我的英语不好
We have a web application in PHP, for our clients we have prepared connect to google analytics UA. I use "google/apiclient": "^2.0", it works that our clients click on button in our administration and then is runned a followed code:
$this->client = new Google_Client();
$this->client->setApplicationName("xxxx");
$this->client->setClientId("xxxx");
$this->client->setClientSecret("xxxx");
$this->client->setScopes(array("https://www.googleapis.com/auth/analytics.readonly"));
$this->client->setRedirectUri("xxxx");
$this->client->setAccessType('offline');
$this->client->setApprovalPrompt("force");
The credentials i get from https://console.cloud.google.com/ -> OAuth 2.0 Client IDs
then the client is redirected to google where he log in, and allow acces to his GA data for our app. then is redirected back with code is generated access token. With this token i can get his GA UA data and show it to graphs in our administration. It works allright, but now i get information that GA UA will be end, and i need to create the same proces for UA V4. But in documentation to GA V4 what i found: https://developers.google.com/analytics/devguides/reporting/data/v1
Is not information how to process it for our clients. There is only authorisation over service account, that i must donwload my own credentials.json to service account but it allow me only acces to my private account, but i need it to work the same as before, so for other clients without having to upload credentials.json. That is, to be redirected to google via OAuth 2.0 Client IDs and allow access to our application to read their data. Is it even possible?
Thank you for help, and sorry for my bad english
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该让您开始。我将Google API PHP客户端库中的OAuth2方法组合在一起,并将其应用于新库。
它不是最佳的,但可以起作用。下面的代码用于安装应用程序而不是Web。它不会主持工作。
This should give you a start. I am combining the OAuth2 methods from the Google API php client library and applying them to the new library.
Its not optimal but it works. Code below is for installed application not web. Its not going to work hosted.
并且请如何获取列表属性的列表流,我有一个代码来获取GA4属性:
在每个属性中,我需要获得GA4流的测量ID。
我需要得到这个
And please how to get list streams of listed properties, I have a code to get GA4 properties:
At every property I need to get measurement ID of GA4 streams.
I need to get this