Skip to content

Receiving 401 Invalid Credentials with oauth2Client #55

@gabrielhpugliese

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

Metadata

Metadata

Labels

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

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions