google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

GMAIL : q parameter isn't working properly.

Open ghost opened this issue 11 years ago • 8 comments

Hi,

I am doing a mail retriever, and everything is working well, except the query filter...

What kind of magic is it ?

When I type my query on gmail or here : https://developers.google.com/gmail/api/v1/reference/users/messages/list

It works and it retrieves the messages.

But when I use the params parameter like that in my nodejs code :

var params = { userId:'me', auth:oauth2Client, q:'from:[email protected] AND after:2015/09/01'}

it retrieve NOTHING

so... When i remove q it retrieves 205 messages ok ok, but come on I need a filter.

ghost avatar Sep 14 '15 13:09 ghost

You have to know that, in 2014/09 when i first developed my application, everything worked well.

ghost avatar Sep 14 '15 13:09 ghost

I found the problem,

For some "reasons", the problem was in the scope of the oauth2... Last year, I used the gmail readonly scope, since believe me or not, I thought that I only needed that to read mails... And it worked pretty well.

But with this readonly, queries in order to search the right mails aren't working at all and retrieve NOTHING now in 2015.

so as a scope, I just used : https://mail.google.com and tadaaaa, working.

ghost avatar Sep 15 '15 09:09 ghost

I ran into the same issue where the query parameter was seemingly ignored. Not sure how it's working for other people, but I ended up having to set the query parameters manually e.g.:

gmail.users.messages.list({ auth:oauthClient, userId: 'me' },{ qs: { q: 'whatever query' } }...

bartam avatar Jan 25 '18 21:01 bartam

@bartam Thanks it worked with this.

AnilRo-Kore avatar Feb 02 '18 09:02 AnilRo-Kore

@bartam this worked for me too! Thanks a ton. This should be included in the official API documentation. There are no instructions in official documentations on how to pass the optional query parameters.

abhanshgiri21 avatar Feb 09 '18 07:02 abhanshgiri21

@bartam Thanks for showing how to manually add query parameters. Nice workaround, I wasn't aware of qs tag.

Amit-L avatar Feb 19 '18 07:02 Amit-L

Since I got comments: The reason the qs param works is because this package calls the google-auth-library package which wraps the request package...if I remember right. So you should be able to pass any of the request parameters here too.

It's also the google-auth-library that's causing the query param not to work here. Probably related to the 1.0.0 release, but it would probably be an easy fix if someone wanted to do a pull request.

bartam avatar Feb 20 '18 03:02 bartam

I still get [ { id: '1673bf99eaf517c2', threadId: '1673bf99eaf517c2' }]

Please what am I doing wrong?

gmail.users.messages.list({userId: 'me', labelIds: ['INBOX']},{ qs: { q: 'Google' } } , (err, res) => {
        if (err) return console.log(`Error getting inbox from gmail: ${err}`);
        console.log(res.data.messages);
 });

I am using "googleapis": "^27.0.0" not google-auth-library

rotimi-best avatar Nov 22 '18 15:11 rotimi-best