Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda