【问题标题】:Google analytics Embeded API - The OAuth client was not foundGoogle Analytics 嵌入 API - 未找到 OAuth 客户端
【发布时间】:2017-02-22 20:51:55
【问题描述】:

我正在尝试创建一个 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>

【问题讨论】:

  • 理想情况下,我想尝试从谷歌分析组件中提取数据并将其放入自定义图表工具中

标签: javascript oauth google-analytics google-oauth google-analytics-api


【解决方案1】:

clientid: 'UA-104xxxx-x'

客户端 ID 是在 Google developer console 上创建的,看起来像这样

1046123799103-dmog5dt4cu055g7pf08gitv3i0rlni6f.apps.googleusercontent.com

网络媒体资源 ID 来自 Google Analyitcs 网站,如下所示

UA-104xxxx-x

Anwser:您发送的内容有误。 Create a New Client ID

【讨论】:

  • 在谷歌开发者控制台哪里可以找到这个?我找到了一个 api 密钥 - 但没有这样的
  • 点击 Google 文档中关于嵌入式 api developers.google.com/analytics/devguides/reporting/embed/v1/… 的说明的链接。您应该创建 Oauth2 凭据而不是公共 API 密钥凭据。如果这没有帮助,我还有一个关于创建 Oauth2 凭据的教程daimto.com/google-developer-console-oauth2
  • 干杯人。我找到了。好的,我将尝试让这个更复杂 - 这里有直接的 api 数据到图表方法。
  • 我不确定我理解您所说的 Direct API 是什么意思。然而,嵌入式 API 使用核心报告 API。 developers.google.com/analytics/devguides/reporting
  • 我的意思是你直接调用的东西——然后它会喷出原始 json,让你用第三方图表轻松代谢。理想情况下,没有橙色按钮等。
猜你喜欢
  • 2017-09-06
  • 1970-01-01
  • 2014-03-27
  • 2015-02-20
  • 2016-03-02
  • 2014-06-18
  • 1970-01-01
  • 2022-11-04
  • 2018-03-24
相关资源
最近更新 更多