Google分析“无效凭据”

时间:2016-12-29 14:10:48

标签: google-analytics google-analytics-api

我编写的代码已发送access_token请求并成功完成 代码在(node.js)

之下
authClient.authorize(function(err, tokens) 
{res.json(tokens);}

当我将此令牌传递到此处成功获得此令牌后,我收到错误“无效凭据”

gapi.analytics.auth.authorize({
    'serverAuth': {
      'access_token': '{{token}}'
    }
});

1 个答案:

答案 0 :(得分:0)

这里你是一个完整的例子

<!DOCTYPE html>
<html>
<head>
  <title>Embed API Demo</title>
</head>
<body>

<section id="timeline"></section>

<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() {

  var IDS = 'ENTER YOUR IDS VAUE HERE'; // e.g. 'ga:1174'
  var ACCESS_TOKEN = 'ENTER VALID ACCESS TOKEN'; // obtained from your service account

  gapi.analytics.auth.authorize({
    serverAuth: {
      access_token: ACCESS_TOKEN
    }
  });

  var timeline = new gapi.analytics.googleCharts.DataChart({
    reportType: 'ga',
    query: {
      'ids': IDS,
      'dimensions': 'ga:date',
      'metrics': 'ga:sessions',
      'start-date': '30daysAgo',
      'end-date': 'yesterday',
    },
    chart: {
      type: 'LINE',
      container: 'timeline'
    }
  }).execute();

});
</script>
</body>
</html>

这是从Google文档中提取的,如需完整参考,请点击here 并检查this链接,如果全部失败,请检查this stackoverflow post