Google-api-nodejs-client: GMAIL : q parameter isn't working properly.

Created on 14 Sep 2015  路  8Comments  路  Source: googleapis/google-api-nodejs-client

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.

triage me

Most helpful comment

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' } }...

All 8 comments

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

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.

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 Thanks it worked with this.

@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.

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

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.

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

Was this page helpful?
0 / 5 - 0 ratings