简体   繁体   English

如何通过Google登录对话框(javascript)无需登录即可访问Google Analytics(分析)API?

[英]How to access Google analytics api WITHOUT logging through google login dialog (javascript)?

I can retrieve analytics data using Core Reporting API v4, but for that I am required to login through google sign in dialog. 我可以使用Core Reporting API v4检索分析数据,但为此,我需要通过google登录对话框登录。

How can I get the data skipping this step ie, I don't to want to login through the Google user interface. 我如何跳过此步骤获取数据,即我不想通过Google用户界面登录。

Turns out I misread the question - it looks like you are looking for a service account . 原来我误解了这个问题-好像您在寻找服务帐户 A service account allows for non-interactive authentication against Google APIs. 服务帐户允许针对Google API进行非交互式身份验证。

You create a service account in the Google API console. 您在Google API控制台中创建一个服务帐户。 There you can download a file with credentials that are used for authentication. 您可以在那里下载带有用于身份验证的凭据的文件。 This is handled non-interactively without opening a browser. 这是在不打开浏览器的情况下以非交互方式处理的。

You need to add the email of the service account to the resource you want to access (eg to your Analytics account). 您需要将服务帐户的电子邮件添加到要访问的资源(例如,您的Analytics(分析)帐户)。

Details are in the link (this is a PHP example, but service accounts work regardless of programming language). 详细信息在链接中(这是一个PHP示例,但是服务帐户可以使用,而无论编程语言如何)。

Old answer: 旧答案:

Somebody has to log in to get the data (GA accounts always need authentication), so if you don't want to log in via the browser you need an intermediary application that authenticates against Google and then publicy exposes the data. 必须有人登录才能获取数据(GA帐户始终需要身份验证),因此,如果您不想通过浏览器登录,则需要一个中间应用程序,该应用程序可以通过Google进行身份验证,然后公开展示数据。

There is a project Google Analytics Super Proxy that does this, however it requires a bit of setup. 有一个项目Google Analytics Super Proxy可以做到这一点,但是需要一些设置。

A simpler way would be to use the Analytics Add-On in a Google Spreadsheet, share that publicly and embed it in your page, or format the output as HTML or JSON via some Apps script and pull it into your page for display. 一种更简单的方法是在Google Spreadsheet中使用Google Analytics(分析)加载项,公开共享并将其嵌入到您的页面中,或者通过某些Apps脚本将输出格式设置为HTML或JSON,然后将其拉入页面进行显示。

Unfortunately you can't.Cause you need to access the report through a private API code.And in the Javascript version, you would be sharing it with public.That's why in case of JS you MUST use the log in button. 不幸的是您不能这样做,因为您需要通过私有API代码访问该报告,而在Javascript版本中,您将与公众共享它,这就是为什么在JS情况下必须使用登录按钮的原因。

Hence the only way to do it without logging in, is by using a server side code like PHP along with the API. 因此,唯一无需登录即可完成此操作的方法是使用服务器端代码(如PHP)和API。

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

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