2

我正在嘗試創建一個可視化Google Anayltics數據的API。谷歌分析嵌入式API - 未找到OAuth客戶端

當我運行此代碼時,它會出現一個橙色按鈕 - 但點擊它會產生「未找到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> 
+0

理想情況下,我想嘗試從Google分析組件中提取數據並將其放入自定義圖表工具 –

回答

3

的clientid: 'UA-104xxxx-X'

客戶端ID上Google developer console創建和看起來像這樣

1046123799103-dmog5dt4cu055g7pf08gitv3i0rlni6f.apps.googleusercontent.com 

網站資源編號是從谷歌Analyitcs網站並看起來像這樣

UA-104xxxx-x 

Anwser:你發錯了。 Create a New Client ID

+0

哪裏可以在Google開發者控制檯上找到?我找到了一個api鍵 - 但沒有這樣 –

+0

請點擊鏈接獲取嵌入式API API上Google文檔的說明https://developers.google.com/analytics/devguides/reporting/embed/v1/getting-started#client -ID 。您應該創建Oauth2憑證而不是公共API密鑰憑證。如果這並沒有幫助我有一個關於創建Oauth2憑據的教程,以及http://www.daimto.com/google-developer-console-oauth2/ – DaImTo

+0

乾杯的人。我找到了。好的,我將嘗試使這更復雜 - 是否有一個直接的API數據圖表方法在這裏。 –

相關問題