我想要的內容:網站應顯示沒有授權的分析數據。從Google AnalyticsAPI獲取數據
我做了什麼:我有一個在谷歌應用程序引擎和啓用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>
我試着看到幾個文件,以獲得服務器授權密鑰,但我沒得到它。
任何人都可以幫助設置服務器身份驗證密鑰,並通過這將我的目的顯示圖表沒有身份驗證將解決?
感謝, 沙拉德·瑞裏
此問答可能有幫助:http://stackoverflow.com/questions/31057968/showing-google-analytics-data-in-real-time/31058732#31058732 –