Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda