title: Is their any way of getting metrics from google ads accounts via api?
body: <p>I was trying to display metrics from google ads accounts that gave me consent via an Oauth prompt. any ways of displaying data from google ads accounts that went through consent prompt? please fix the code listed below if possible so i can display data on a table via getElementById if possible.</p>
  <p>Code I tried</p>
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;script&gt;
  var YOUR_CLIENT_ID = '504111780457-nslu2gim01j3c7optfbvjkd7trdgjgk9.apps.googleusercontent.com';
  var YOUR_REDIRECT_URI = 'https://prompt.sewellstephens.com/api';
  var fragmentString = location.hash.substring(1);
  
  // Parse query string to see if page request is coming from OAuth 2.0 server.
  var params = {};
  var regex = /([^&amp;=]+)=([^&amp;]*)/g, m;
  while (m = regex.exec(fragmentString)) {
  params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
  }
  if (Object.keys(params).length &gt; 0) {
  localStorage.setItem('oauth2-test-params', JSON.stringify(params) );
  if (params['state'] &amp;&amp; params['state'] == 'try_sample_request') {
    trySampleRequest();
  }
  }
  
  // If there's an access token, try an API request.
  // Otherwise, start OAuth 2.0 flow.
  function trySampleRequest() {
  var params = JSON.parse(localStorage.getItem('oauth2-test-params'));
  if (params &amp;&amp; params['access_token']) {
    var xhr = new XMLHttpRequest();
    xhr.open('GET',
        'https://googleads.googleapis.com/v3/customers/1234567890/metrics:mutate?fields=user&amp;' +
        'access_token=' + params['access_token']);
    xhr.onreadystatechange = function (e) {
      if (xhr.readyState === 4 &amp;&amp; xhr.status === 200) {
        console.log(xhr.response);
      } else if (xhr.readyState === 4 &amp;&amp; xhr.status === 401) {
        // Token invalid, so prompt for user permission.
        oauth2SignIn();
      }
    };
    xhr.send(null);
  } else {
    oauth2SignIn();
  }
  }
  
  /*
   * Create form to request access token from Google's OAuth 2.0 server.
   */
  function oauth2SignIn() {
  // Google's OAuth 2.0 endpoint for requesting an access token
  var oauth2Endpoint = 'https://accounts.google.com/o/oauth2/v2/auth';
  
  // Create element to open OAuth 2.0 endpoint in new window.
  var form = document.createElement('form');
  form.setAttribute('method', 'GET'); // Send as a GET request.
  form.setAttribute('action', oauth2Endpoint);
  
  // Parameters to pass to OAuth 2.0 endpoint.
  var params = {'client_id': YOUR_CLIENT_ID,
                'redirect_uri': YOUR_REDIRECT_URI,
                'scope': 'https://www.googleapis.com/auth/adwords',
                'state': 'try_sample_request',
                'include_granted_scopes': 'true',
                'response_type': 'token'};
  
  // Add form parameters as hidden input values.
  for (var p in params) {
    var input = document.createElement('input');
    input.setAttribute('type', 'hidden');
    input.setAttribute('name', p);
    input.setAttribute('value', params[p]);
    form.appendChild(input);
  }
  
  // Add form to page and submit it to open the OAuth 2.0 endpoint.
  document.body.appendChild(form);
  form.submit();
  }
  &lt;/script&gt;
  
   &lt;button onclick=&quot;trySampleRequest();&quot;&gt;Prompt Consent&lt;/button&gt;
  &lt;/body&gt;
  &lt;/html&gt;'''
  </code></pre>
  <p>I don't know where to put the developer token and need someone to fix this code if possible. I have been trying to do this api call and its been a nightmare trying to fix this code up so that i can display data from google ads accounts via a consent prompt.</p>