使用新的Google Analytics核心报告API和OAuth 2.0进行身份验证
问题描述:
Google Analytics的新“Core Reporting API”(版本3.0)“建议使用OAuth 2.0授权请求”(citation)。尽管如此,它的文档还不清楚如何做到这一点。 (它说:“当你创建你的应用程序,你注册它与谷歌”(citation),但一个shell脚本算作一个“应用程序”??如果是这样,我应该注册bash脚本the "APIs Console",这并没有给。使用Analytics(分析)2.3版本上怎么做任何指导),我运行bash脚本:使用新的Google Analytics核心报告API和OAuth 2.0进行身份验证
#!/bin/bash
# generates an XML file
googleAuth="$(curl https://www.google.com/accounts/ClientLogin -s \
-d Email=foo \
-d Passwd=bar \
-d accountType=GOOGLE \
-d source=curl-dataFeed-v2 \
-d service=analytics \
| awk /Auth=.*/)"
# ...
feedUri="https://www.google.com/analytics/feeds/data\
?ids=$table\
&start-date=$SD\
&end-date=$ED\
&dimensions=baz\
&metrics=xyzzy\
&prettyprint=true"
# ...
curl $feedUri --silent \
--header "Authorization: GoogleLogin $googleAuth" \
--header "GData-Version: 2" \
| awk # ...
我怎么会做这样的事情—,抓住任何登录令牌,我需要并将其发送回—脚本为新的分析?
(顺便说一句,是的,我知道结果会是JSON,而不是XML)。
答
下面是一个示例脚本
googleAuth="$(curl https://www.google.com/accounts/ClientLogin -s \
-d Email=$USER_EMAIL \
-d Passwd=$USER_PASS \
-d accountType=GOOGLE \
-d source=curl-accountFeed-v1 \
-d service=analytics \
| grep "Auth=" | cut -d"=" -f2)"
feedUri="https://www.googleapis.com/analytics/v3/data/ga\
?start-date=$START_DATE\
&end-date=$END_DATE\
&ids=ga:$PROFILE_ID\
&dimensions=ga:userType\
&metrics=ga:users\
&max-results=50\
&prettyprint=false"
curl $feedUri -s --header "Authorization: GoogleLogin auth=$googleAuth"
我不需要如上的整个脚本。事实上,解释会更好(所以我可以根据需要生成和修改脚本)。 – msh210
转发至http://groups.google.com/group/google-analytics-data-export-api/browse_frm/thread/d31118126fbd5485 – msh210
如果您有兴趣,我在此回答:http://groups.google .com/group/google-analytics-data-export-api/browse_thread/thread/d31118126fbd5485# – 2011-12-13 17:53:15