Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
How do I get the correct access token for my Google Analytics Embed API app?

I have this code made by Google and I want to make server-side authentication, but the access token I get on https://developers.google.com/oauthplayground/ doesn't seem to work. What am I doing wrong?

When I use client-side authentication it works, but I need to show the charts without login. And of course, I deleted the access token just to post.

<script>
gapi.analytics.ready(function() {

  // Step 3: Authorize the user.

  var CLIENT_ID = 'Insert your client ID here';

  gapi.analytics.auth.authorize({
  serverAuth: {
    access_token: ' '
  }
});

  // Step 4: Create the view selector.

  var viewSelector = new gapi.analytics.ViewSelector({
    container: 'view-selector'
  });

  // Step 5: Create the timeline chart.

  var timeline = new gapi.analytics.googleCharts.DataChart({
    reportType: 'ga',
    query: {
      'dimensions': 'ga:date',
      'metrics': 'ga:sessions',
      'start-date': '30daysAgo',
      'end-date': 'yesterday',
    },
    chart: {
      type: 'LINE',
      container: 'timeline'
    }
  });

  // Step 6: Hook up the components to work together.

  gapi.analytics.auth.on('success', function(response) {
    viewSelector.execute();
  });

  viewSelector.on('change', function(ids) {
    var newIds = {
      query: {
        ids: ids
      }
    }
    timeline.set(newIds).execute();
  });
});
</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

When I use client-side authentication it works, but I need to show the charts without login. And of course, I deleted the access token just to post.

The data you are trying to access is private user data in order to access private user data you need to be authorized by the user. The only way to do that is to request access of the user. To do that we use Oauth2.

Oauth2 access tokens expire after an hour so what you are trying to do is not going to work. The token you have created though google oauth playground is an access token.

You need to create web browser credentials on google cloud console. make sure to set the JavaScript origin for your local server as well, for example: http://localhost:8080.

This video will walk you though how to create the credentials. web application redetinals

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!