【发布时间】:2021-11-27 19:28:45
【问题描述】:
我有 Google 制作的这段代码,我想进行服务器端身份验证,但我在 https://developers.google.com/oauthplayground/ 上获得的访问令牌似乎不起作用。我做错了什么?
当我使用客户端身份验证时,它可以工作,但我需要在没有登录的情况下显示图表。当然,我删除访问令牌只是为了发布。
<script>
gapi.analytics.ready(function() {
// Step 3: Authorize the user.
var CLIENT_ID = 'Insert your client ID here';
gapi.analytics.auth.authorize({
serverAuth: {
access_token: ' '
}
});
// 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'
}
});
// 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>
【问题讨论】:
标签: javascript oauth-2.0 google-analytics google-oauth google-analytics-api