Skip to content

credentials.expiry_date problem #353

@MikeFang

Description

@MikeFang

I am a newer on Node.Js. Could anyone do me a favor? The following code I edited from the example oauth2.js and my environmet is Windows 7. I got the messages from my condole, the major error occurred at the c:\tmp\foo\node_modules\googleapis\lib\auth\oauth2client.js:245

var expiryDate = credentials.expiry_date;
                              ^
TypeError: Cannot read property 'expiry_date' of undefined

Console's log message:

c:\tmp\foo>node index
listening on *:3000
connect sucessfully!!
code: 4/CYoOSmpMEII1AJlGgxKx4z-E7vAGXzch_UecGOy3zFk.gqFpAiq9EK8cgrKXntQAax0gfEzk
lQI

c:\tmp\foo\node_modules\googleapis\lib\auth\oauth2client.js:245
  var expiryDate = credentials.expiry_date;
                              ^
TypeError: Cannot read property 'expiry_date' of undefined
    at OAuth2Client.request (c:\tmp\foo\node_modules\googleapis\lib\auth\oauth2c
lient.js:245:31)
    at createAPIRequest (c:\tmp\foo\node_modules\googleapis\lib\apirequest.js:18
9:22)
    at Object.Plus.people.get (c:\tmp\foo\node_modules\googleapis\apis\plus\v1.j
s:319:14)
    at c:\tmp\foo\index.js:95:15
    at c:\tmp\foo\index.js:110:7
    at c:\tmp\foo\node_modules\googleapis\lib\auth\oauth2client.js:144:7
    at Request._callback (c:\tmp\foo\node_modules\googleapis\lib\transporters.js
:67:30)
    at self.callback (c:\tmp\foo\node_modules\googleapis\node_modules\request\re
quest.js:373:22)
    at Request.emit (events.js:95:17)
    at Request.onRequestError (c:\tmp\foo\node_modules\googleapis\node_modules\r
equest\request.js:971:8)

c:\tmp\foo>

Code:

app.get('/oauth2callback', function(req, res) {
   var code = req.query.code;
    console.log('code: '+code);
    var CLIENT_ID = 'id here';
    var CLIENT_SECRET = 'secret here';
    var REDIRECT_URL = 'http://localhost:3000/oauth2callback';
    var google = require('googleapis');
    var OAuth2 = google.auth.OAuth2;
    var plus = google.plus('v1');
    var oauth2Client = new OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL);

// retrieve an access token
getAccessToken(oauth2Client, function() {
  // retrieve user profile
  plus.people.get({ userId: 'me', auth: oauth2Client }, function(err, profile) {
    if (err) {
      console.log('An error occured', err);
      return;
    }
    console.log(profile.displayName, ':', profile.tagline);
  });
}); 

function getAccessToken(oauth2Client, callback) {
    // request access token
    oauth2Client.getToken(code, function(err, tokens) {
      // set tokens to the client
      // TODO: tokens should be set by OAuth2 client.
      oauth2Client.setCredentials(tokens);
      callback();
    });
}   
});

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