It is currently July 27th, 2024, 2:32 pm
Tips and Tricks from the Rainmeter Community
mistic100
Posts: 35 Joined: October 12th, 2014, 5:27 pm
Post
by mistic100 » May 28th, 2016, 3:04 pm
Hello
Here is a simple trick to display the number of new mails in your Gmail, Outlook, IMAP, etc. mailboxes.
It is based on
https://nylas.com cloud API (which can be hosted on your own server if you care about absolute privacy).
Register on Nylas Developer Program https://developer.nylas.com/register
On the "Accounts" tab of the developer console, add your mail account, any big provider is supported as well as any IMAP account
You will be given an access token store it preciously, you won't be able to get it later (unless deleting the account)
Now simply use the WebParser plugin with basic auth to get the mail count
Code: Select all
[mMailCount]
Measure=Plugin
Plugin=WebParser
UpdateRate=60
URL=https://YOUR_TOKEN@api.nylas.com/threads?in=inbox&view=count&unread=true
RegExp=(?siU)"count": ([0-9]+)
StringIndex=1
Have fun
mistic100
Posts: 35 Joined: October 12th, 2014, 5:27 pm
Post
by mistic100 » May 29th, 2016, 1:00 pm
Yesterday it was working well, but today I systematically get an error in WebParser dump :
Code: Select all
{
"message": "Could not verify access credential.",
"type": "invalid_request_error"
}
though it works when I access the API with Firefox.
Perhaps the Rainmeter User-Agent got blacklisted.
jsmorley
Developer
Posts: 22649 Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA
Post
by jsmorley » May 29th, 2016, 1:03 pm
mistic100 wrote: Yesterday it was working well, but today I systematically get an error in WebParser dump :
Code: Select all
{
"message": "Could not verify access credential.",
"type": "invalid_request_error"
}
though it works when I access the API with Firefox.
Perhaps the Rainmeter User-Agent got blacklisted.
Perhaps, or you might have overrun some hourly/daily/monthly limit on calls to the API during your testing.
mistic100
Posts: 35 Joined: October 12th, 2014, 5:27 pm
Post
by mistic100 » May 29th, 2016, 1:09 pm
I don't think so, it still works from the browser or curl
Last edited by mistic100 on May 29th, 2016, 1:19 pm, edited 1 time in total.
jsmorley
Developer
Posts: 22649 Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA
Post
by jsmorley » May 29th, 2016, 1:17 pm
You might be able to actually use cURL.exe with the RunCommand plugin and get the information that way. Either directly from STDOUT with RunCommand and RegExpSubstitute, or by downloading the XML to a file and using WebParser to parse the local file created. I believe in cURL you can set any User Agent string you want.
mistic100
Posts: 35 Joined: October 12th, 2014, 5:27 pm
Post
by mistic100 » May 29th, 2016, 1:21 pm
Interesting, I'll try, thank you.
I also contacted Nylas support to know if there was any changes in the BasicAuth process.
mistic100
Posts: 35 Joined: October 12th, 2014, 5:27 pm
Post
by mistic100 » May 29th, 2016, 2:53 pm
Working measure with curl :
Code: Select all
[mMailCountTick]
Measure=Calc
UpdateDivider=60
OnUpdateAction=[!CommandMeasure mMailCount "Run"]
[mMailCount]
Measure=Plugin
Plugin=RunCommand
Parameter=curl -s "https://#Token#@api.nylas.com/threads?in=inbox&view=count&unread=true"
OutputType=ANSI
RegExpSubstitute=1
Substitute='"count": ':"","{":"","}":""," ":"","#CRLF#":""
jsmorley
Developer
Posts: 22649 Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA
Post
by jsmorley » May 29th, 2016, 3:00 pm
Cool beans...
jsmorley
Developer
Posts: 22649 Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA
Post
by jsmorley » June 1st, 2016, 1:39 pm
FYI, we have added the capability to set a custom User Agent String to WebParser, so you won't need to us cURL for this purpose going forward.
https://forum.rainmeter.net/viewtopic.php?p=124153#p124153
mistic100
Posts: 35 Joined: October 12th, 2014, 5:27 pm
Post
by mistic100 » June 1st, 2016, 2:17 pm
I'm not 100% sure the problem is the user agent but a redirection with cookie auth.