我正在尝试创建一个api来可视化google anayltics数据。
当我运行此代码时,它会出现一个橙色按钮 - 但是点击它会产生“找不到OAuth客户端”。错误?
使用此代码作为示例。 https://ga-dev-tools.appspot.com/embed-api/basic-dashboard/
<html>
<head>
<script>
(function(w,d,s,g,js,fs){
g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(f){this.q.push(f);}};
js=d.createElement(s);fs=d.getElementsByTagName(s)[0];
js.src='https://apis.google.com/js/platform.js';
fs.parentNode.insertBefore(js,fs);js.onload=function(){g.load('analytics');};
}(window,document,'script'));
</script>
<script>
gapi.analytics.ready(function() {
/**
* Authorize the user immediately if the user has already granted access.
* If no access has been created, render an authorize button inside the
* element with the ID "embed-api-auth-container".
*/
gapi.analytics.auth.authorize({
container: 'embed-api-auth-container',
clientid: 'UA-104xxxx-x'
});
/**
* Create a new ViewSelector instance to be rendered inside of an
* element with the id "view-selector-container".
*/
var viewSelector = new gapi.analytics.ViewSelector({
container: 'view-selector-container'
});
// Render the view selector to the page.
viewSelector.execute();
/**
* Create a new DataChart instance with the given query parameters
* and Google chart options. It will be rendered inside an element
* with the id "chart-container".
*/
var dataChart = new gapi.analytics.googleCharts.DataChart({
query: {
metrics: 'ga:sessions',
dimensions: 'ga:date',
'start-date': '30daysAgo',
'end-date': 'yesterday'
},
chart: {
container: 'chart-container',
type: 'LINE',
options: {
width: '100%'
}
}
});
/**
* Render the dataChart on the page whenever a new view is selected.
*/
viewSelector.on('change', function(ids) {
dataChart.set({query: {ids: ids}}).execute();
});
});
</script>
</head>
<body>
<div id="embed-api-auth-container"></div>
<div id="chart-container"></div>
<div id="view-selector-container"></div>
</body>
</html>
答案 0 :(得分:3)
clientid:'UA-104xxxx-x'
客户端ID在Google developer console上创建,看起来像这样
task makeZip(type: Zip) {
baseName 'libsZip'
from configurations.compile
exclude { it.file in configurations.common.files }
网络媒体资源ID来自Google Analyitcs网站,看起来像这样
1046123799103-dmog5dt4cu055g7pf08gitv3i0rlni6f.apps.googleusercontent.com
Anwser:你发错了。 Create a New Client ID