[英]How to fetch data from my google analytics account to use on site?
Consider that I am owner of http://ethernalsite.com 认为我是http://ethernalsite.com的所有者
On my website i've added google analytics script and it's happily collecting data about my precious visitors. 在我的网站上,我添加了Google Analytics(分析)脚本,它很高兴地收集了有关我的宝贵访客的数据。
I would like to create page views counter. 我想创建浏览量计数器。 How I can fetch data from my own account? 如何从自己的帐户中获取数据?
I mean, from site's account on which data is collected. 我的意思是,从网站的帐户中收集数据。
I've tried this: 我已经试过了:
create browser token on google's developer console and allow access for ethernalsite.com/*
在Google开发人员控制台上创建浏览器令牌 ,并允许访问ethernalsite.com/*
I've got something like: xxxxSyCl5wAzQVSxxxxxKHFcxn6Uxzi-skoFZgo 我有类似的东西:xxxxSyCl5wAzQVSxxxxxKHFcxn6Uxzi-skoFZgo
make ajax get on client(javascript) side: https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A00263622&metrics=ga%3AuniquePageviews&start-date=2014-08-19&end-date=2014-09-02&max-results=50&key= 使ajax进入客户端(javascript)端: https : //www.googleapis.com/analytics/v3/data/ga?ids= ga%3A00263622&metrics=ga%3AuniquePageviews&start-date=2014-08-19&end-date =2014- 09-02&max-results = 50&key = {KEY} {键}
I've got the following response for ajax get query(firebug) 我对ajax get query(firebug)有以下响应
"NetworkError: 401 Unauthorized - https://www.googleapis.com/analytics/v3/data
/ga?ids=ga%3A00263622&metrics=ga%3AuniquePageviews&start-date=2014-08-19&
end-date=2024-09-02&max-results=50&key=xxxxSyCl5wAzQVSxxxxxKHFcxn6Uxzi-skoFZgo"
With content: 带有内容:
{"error":{"errors":[{"domain":"global","reason":"required",
"message":"LoginRequired","locationType":"header","location":"Authorization"}],
"code":401,"message":"Login Required"}}
In the future I would like to cache this value in the server side and allow client to fetch this data from my server every minute. 将来,我想将此值缓存在服务器端,并允许客户端每分钟从我的服务器获取此数据。 If you also have tips about solving this problem using python i would be grateful. 如果您还有使用python解决此问题的技巧,我将不胜感激。
The Google Developer Console will only give you the CLIENT_ID and CLIENT_SECRET. Google Developer Console仅会为您提供CLIENT_ID和CLIENT_SECRET。 With these keys you will be able to generate an ACCESS_TOKEN and you will have to change your query string to 使用这些键,您将能够生成ACCESS_TOKEN,并且必须将查询字符串更改为
?ids=ga%3A00263622&metrics=ga%3AuniquePageviews&start-date=2014-08-19&end-date=2024-09-02&max-results=50&access_key=xxxxACCESS_KEYxxxx&_src=explorer
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.