Skip to content

Google analytics api 401 error Login required #190

@anyatran

Description

@anyatran

I wanted to get data from my google analytics without OAuth and im getting 401 error. Currently i'm passing only API Key (I can't find Simple API Key since the design has changed). Here's my code:

function init() {
    gapi.client.setApiKey(apiKey);
    window.setTimeout(gapi.client.load('analytics', 'v3', makeApiCall), 1);
  }

function makeApiCall() {
    gapi.client.analytics.data.ga.get({
      'ids': document.getElementById('table-id').value,
      'start-date': document.getElementById('start-date').value,
      'end-date': document.getElementById('end-date').value,
      'metrics': 'ga:visits'
    }).execute(handleCoreReportingResults);
  }

 function handleCoreReportingResults(results) {
    if (!results.code) {
      console.log('Query Success');

    } else {
      console.log('There was an error: ' + results.message);
    }
}

I also tried to create a Service account but I'm not sure how can I use it here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions