SpiderStrategies / node-gmail-api

Node module to interact with the gmail api
ISC License
154 stars 29 forks source link

Invalid credentials #9

Closed nyarenbee closed 9 years ago

nyarenbee commented 9 years ago

Am I missing anything? not sure what I should be putting in 'key'. It would be great if you could provide complete example.

var Gmail = require('node-gmail-api')
  , gmail = new Gmail('MY gmail API key')
  , s = gmail.messages('label:inbox', {max: 10})

s.on('data', function (d) {
  console.log(d.snippet)
})

Getting:

error: Invalid Credentials
    at Request._callback (/Users/nbhattarai/source/playground/node_modules/node-gmail-api/index.js:59:35)
    at Request.self.callback (/Users/nbhattarai/source/playground/node_modules/request/request.js:354:22)
    at Request.emit (events.js:98:17)
    at Request.<anonymous> (/Users/nbhattarai/source/playground/node_modules/request/request.js:1207:14)
    at Request.emit (events.js:117:20)
    at IncomingMessage.<anonymous> (/Users/nbhattarai/source/playground/node_modules/request/request.js:1153:12)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:943:16
nathanbowser commented 9 years ago

Check out this closed issue where someone reported a similar issue: https://github.com/SpiderStrategies/node-gmail-api/issues/2

Specifically this commit: https://github.com/SpiderStrategies/node-gmail-api/commit/293c4080a30f74480fda6bd4c418fec61fc4a538

You'll need to read up on oauth, specifically how google handles oauth. Once you obtain the oauth key, you can use this module.

casalot commented 8 years ago

@nathanbowser, I'm also getting the Invalid Credentials error. When you mentioned the oauth key, which key is this? The Client ID or Client Secret on the Google Developers Dashboard?

And, if using Service Account Keys, which key should this be?

nathanbowser commented 8 years ago

I'm not sure, @casalot. You'll have to experiment with your oauth setup. We use passport and authenticate like this:

  passport.use('google-apps', new GoogleStrategy({
    clientID: clientId,
    clientSecret: clientSecret,
    callbackURL: callback
  }, function (accessToken, tokenSecret, params, profile, done) {
    // Use accessToken when communicating with the node-gmail-api
  })