Google嵌入式分析API-找不到OAuth客户端

Google analytics Embeded API - The OAuth client was not found

本文关键字:找不到 OAuth 客户端 API- 嵌入式 Google      更新时间:2023-09-26

我正在尝试创建一个api来可视化谷歌分析数据。

当我运行此代码时,它会出现一个橙色按钮,但单击它会产生一个"未找到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>

客户端ID:'UA-104xxxx-x'

客户端id是在谷歌开发者控制台上创建的,看起来像这个

1046123799103-dmog5dt4cu055g7pf08gitv3i0rlni6f.apps.googleusercontent.com

一个web属性id来自Google Analytics网站,看起来像这个

UA-104xxxx-x

安:你寄错东西了。创建新客户端ID