title: Google Analytics OAuth2 Client ID Localhost
body: <p>I am trying out this Embed API tutorial which doesn't seem to be working for me:
  <a href="https://developers.google.com/analytics/devguides/reporting/embed/v1/getting-started" rel="nofollow noreferrer">https://developers.google.com/analytics/devguides/reporting/embed/v1/getting-started</a></p>
  <p>This is my code following, with the steps followed to create the client ID:</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Embed API Demo&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;!-- Step 1: Load the Embed API library. --&gt;
          &lt;script&gt;
  (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'));
          &lt;/script&gt;
          &lt;!-- Step 2: Add HTML containers to host the dashboard components. --&gt;
          &lt;div id=&quot;embed-api-auth-container&quot;&gt;&lt;/div&gt;
          &lt;div id=&quot;chart-container&quot;&gt;&lt;/div&gt;
          &lt;div id=&quot;view-selector-container&quot;&gt;&lt;/div&gt;
          &lt;!-- Step 3: Write the dashboard code. --&gt;
          &lt;script&gt;
  
  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 &quot;embed-api-auth-container&quot;.
     */
    gapi.analytics.auth.authorize({
      container: 'embed-api-auth-container',
      clientid: 'CLIENT ID' &lt;!-- I put my actual client ID here in the file --&gt;
    });
  
  
    /**
     * Create a new ViewSelector instance to be rendered inside of an
     * element with the id &quot;view-selector-container&quot;.
     */
    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 &quot;chart-container&quot;.
     */
    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();
    });
  
  });
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>I follow the steps perfectly, but it does not render in the page and I don't get any helpful errors, just a blank page.</p>
  <p>My question is: Do I have to be using this on an authorised domain? There are authorised domain steps, but it does not accept localhost (which doesn't make sense when you're just trying out an app). So I am currently opening this file in localhost:5500/home.html. I added my own html in there just to check the actual file is loading, which it is. The JS just isn't rendering, so I am assuming it is a problem with my client ID and the setup with authorised domains?</p>
  <p>Does anyone have any experience of this, and can suggest a way to test google oauth2 functions on localhost?</p>
  <p>Thanks.</p>