Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh token did not work properly #583

Closed
abhaygarg opened this issue May 17, 2016 · 3 comments
Closed

Refresh token did not work properly #583

abhaygarg opened this issue May 17, 2016 · 3 comments
Assignees

Comments

@abhaygarg
Copy link

abhaygarg commented May 17, 2016

Hi , I am using google api nodejs , I try to get data from google Anaytics

var google = require('googleapis');
var OAuth2Client = google.auth.OAuth2;
var CLIENT_ID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
var CLIENT_SECRET = 'xxxxxxxxxxxxxxxxxxxxxx';
//var REDIRECT_URL = 'http://yieldops.co/oauth2Callback';
var REDIRECT_URL = 'http://localhost:8000/oauth2Callback';
var oauth2Client = new OAuth2Client(CLIENT_ID, CLIENT_SECRET,REDIRECT_URL);

var credentials={}
credentials.expiry_date= "1463514280558",
credentials['refresh_token']="aaaaaaaaa"
credentials['access_token']="aaaaaaaaaaaaaaa"
oauth2Client.setCredentials(credentials)

var gauth = {
    'auth': outh2Client,
    'ids': 'ga:101' ,
    'start-date': '2016-01-01',
    'end-date': 'today',
    'metrics': 'ga:impressions,ga:sessions,ga:pageviews',
    'dimensions': 'ga:date'
}

analytics.data.ga.get(gauth, function (err, gaData) {
    console.log("err 1234",err)
    console.log("gaData ",gaData)
    //console.log("ga",Object.keys(gaData))
})

Now the problem is if access token is not expire then it give me data , and if access token is expire then it gave me 400 error Invalid grant . And if I remove expiry_date from credentials then it gave me error
{ [Error: Invalid Credentials]
code: 401,
errors:
[ { domain: 'global',
reason: 'authError',
message: 'Invalid Credentials',
locationType: 'header',
location: 'Authorization' } ] }

@ddimitrioglo
Copy link

Confirm! I have the same issue...

@courthead
Copy link

@abhaygarg I'm not sure if this is your issue, but shouldn't expiry_date be set to an integer, not a string?

@JustinBeckwith
Copy link
Contributor

Greetings folks! A few things here:

  1. You should never really set the expiry_date yourself. We populate that when we acquire an access_token from the server.

  2. If you are setting a refresh_token - you need to make sure that the service you're trying to use requires the same scopes as those used to request the initial refresh_token. Otherwise, you will end up with invalid_grant :)

We've made a lot of changes here recently. If you're still running into problems - please do let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants