无法使用API文档显示分析

无法使用API文档显示分析,api,analytics,Api,Analytics,我注意到: 并创建了以下内容: <!DOCTYPE html> <html> <head> <title>Analytics Test</title> </head> <body> <script> (function(w,d,s,g,js,fs){ g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(f){this.q.push(f)

我注意到:

并创建了以下内容:

<!DOCTYPE html>
<html>
<head>
<title>Analytics Test</title>
</head>
<body>

<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>

<div id="embed-api-auth-container"></div>
<div id="chart-container"></div>
<div id="view-selector-container"></div>

<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-1234567-00',
  });


  /**
   * 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>

</body>
</html>

分析测试
(功能(w、d、s、g、js、fs){
g=w.gapi | |(w.gapi={});g.analytics={q:[],ready:function(f){this.q.push(f);};
js=d.createElement;fs=d.getElementsByTagName[0];
js.src=https://apis.google.com/js/platform.js';
fs.parentNode.insertBefore(js,fs);js.onload=function(){g.load('analytics');};
}(窗口、文档、“脚本”);
gapi.analytics.ready(函数(){
/**
*如果用户已授予访问权限,则立即授权用户。
*如果未创建访问权限,请在
*ID为“嵌入api身份验证容器”的元素。
*/
gapi.analytics.auth.authorize({
容器:“嵌入api身份验证容器”,
客户编号:“UA-1234567-00”,
});
/**
*创建新的ViewSelector实例以在
*id为“视图选择器容器”的元素。
*/
var viewSelector=new gapi.analytics.viewSelector({
容器:“视图选择器容器”
});
//将视图选择器呈现到页面。
viewSelector.execute();
/**
*使用给定的查询参数创建新的DataChart实例
*和谷歌图表选项。它将在一个元素中呈现
*id为“图表容器”。
*/
var dataChart=new gapi.analytics.googleCharts.dataChart({
查询:{
指标:“ga:会话”,
维度:“ga:日期”,
‘开始日期’:‘30天Sago’,
“结束日期”:“昨天”
},
图表:{
容器:“图表容器”,
键入:“行”,
选项:{
宽度:“100%”
}
}
});
/**
*每当选择新视图时,在页面上呈现dataChart。
*/
viewSelector.on('change',函数(id){
set({query:{ids:ids}}).execute();
});
});
但是在访问页面时什么也看不到

我检查了,API处于活动状态,但该域不在referers列表中,所以我添加了它,但仍然没有任何内容

有什么想法吗

你的

clientID: 'UA-XXXXXXX-XX'
不是正确的客户端ID。这实际上应该如下所示:

clientID: 'XXXXXX.apps.googleusercontent.com'
相反,请尝试在上创建一个项目。在“凭据”选项卡下,可以创建新的客户端ID

如果更简单的话,谷歌有一些分步说明,可以看到