【发布时间】:2015-10-01 01:54:24
【问题描述】:
我想要什么:网站应该在未经授权的情况下显示分析数据。
我做了什么:我在谷歌应用引擎上有一个应用,启用了 API 并创建了一个提供 json 文件的服务帐户。
我尝试做同样的事情:https://ga-dev-tools.appspot.com/embed-api/custom-components/,但没有成功。
然后我遇到了这个问题:http://code.google.com/p/analytics-issues/issues/detail?id=496 并将我的代码更改为这样
<!DOCTYPE html>
<html>
<head>
<title>Embed API Demo</title>
</head>
<body>
<!-- Step 1: Create the containing elements. -->
<section id="auth-button"></section>
<section id="view-selector"></section>
<section id="timeline"></section>
<!-- Step 2: Load the library. -->
<script>
(function(w,d,s,g,js,fjs){
g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(cb){this.q.push(cb)}};
js=d.createElement(s);fjs=d.getElementsByTagName(s)[0];
js.src='https://apis.google.com/js/platform.js';
fjs.parentNode.insertBefore(js,fjs);js.onload=function(){g.load('analytics')};
}(window,document,'script'));
</script>
<script>
gapi.analytics.ready(function() {
// Step 3: Authorize the user.
gapi.analytics.auth.authorize({
serverAuth: '<server auth key>'
});
// Step 4: Create the view selector.
var viewSelector = new gapi.analytics.ViewSelector({
container: 'view-selector'
});
// Step 5: Create the timeline chart.
var timeline = new gapi.analytics.googleCharts.DataChart({
reportType: 'ga',
query: {
'dimensions': 'ga:date',
'metrics': 'ga:sessions',
'start-date': '30daysAgo',
'end-date': 'yesterday',
},
chart: {
type: 'LINE',
container: 'timeline'
}
});
// YOU MUST CALL THIS MANUALLY HERE INSTEAD OF WAITING FOR CALLBACK
viewSelector.execute();
// Step 6: Hook up the components to work together.
gapi.analytics.auth.on('success', function(response) {
viewSelector.execute();
});
viewSelector.on('change', function(ids) {
var newIds = {
query: {
ids: ids
}
}
timeline.set(newIds).execute();
});
});
</script>
</body>
</html>
我尝试查看几个文档以获取服务器身份验证密钥,但未能获得。
任何人都可以帮助设置服务器身份验证密钥,这样我就可以解决我在没有身份验证的情况下显示图表的目的吗?
谢谢, 沙拉德索尼
【问题讨论】:
-
此问答可能会有所帮助:stackoverflow.com/questions/31057968/…
标签: google-app-engine google-analytics