Skip to content

Receiving 401 Invalid Credentials with oauth2Client #55

Closed

Description

@gabrielhpugliese

I get the access_token and refresh_token through another process (Meteor OAuth) and tries to pass it to the oauth2Client.credentials, but it's not refreshing:

[GA ERROR] getData:  { code: 401,
  message: 'Invalid Credentials',
  data: 
   [ { domain: 'global',
       reason: 'authError',
       message: 'Invalid Credentials',
       locationType: 'header',
       location: 'Authorization' } ] }

The code:

function getData (user, params) {
    var googleapis = Meteor.require('googleapis'),
        OAuth2Client = googleapis.OAuth2Client,
        oauth2Client = new OAuth2Client(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL);
    var accessToken = user.services.google.accessToken,
           refreshToken = user.services.google.refreshToken; //works

    oauth2Client.credentials = {
        access_token: accessToken,
        refresh_token: refreshToken
    };
    googleapis.discover('analytics', 'v3').execute(function (err, client) {
            if (err) {
                console.log('[GA ERROR] getClient: ', err);
                return;
            }
            client.analytics.data.ga
                .get(params)
                .withAuthClient(oauth2Client)
                .execute(function (err, result) {
                    if (err) {
                        console.log('[GA ERROR] getData: ', err);
                        return;
                    }
                    console.log(result)
            });
    });
}

Can you give me a light ? I'm struggling with it for days.
Thanks

Activity

  1. gabrielhpugliese commented on Jul 3, 2013

    @gabrielhpugliese
    Author

    Found the problem. I'm invalidating the refresh_token on production when I try to test on development.

  2. domino14 commented on Oct 21, 2015

    @domino14

    Hi Gabriel, could you explain what you mean? I think I'm seeing the same problem, where on development it doesn't refresh properly, but it works on production?

  3. gabrielhpugliese commented on Oct 23, 2015

    @gabrielhpugliese
    Author

    In that case I think I was trying to get a token generated from an app X created on Console API but with a client_id/secret from an app Y (probably because I dumped the db and restored on local db)

  4. verixomumbai commented on Mar 11, 2016

    @verixomumbai

    Hi i m getting same issue when i am calling enroll of EMM Google api using OAuth. actually i have service_account json which i got from google console. and using that i m creating Google credential instance and initialize HttpRequest to call enroll. please help me out what i m doing wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

🚨This issue needs some love.triage meI really want to be triaged.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions