- What was the issue(s)?
What is Google Alerts?
For those who are not familiar with Google Alerts - it is a simple service which lets you create kind of "Internet Watcher" for given search terms.
Some of the search term you can create a watcher for:
- "STEEM OR SBD OR steemit"
- "Donald Trump"
more here: https://www.google.com/alerts
If you think about it longer, it is a brilliant service which you can use widely. But it has a major drawback - Google does not provide a public API for it.
A couple of people started to use it as well. And it was fine, until Google has changed the way we can authenticate pragmatically. It started to require CAPTCHA ( :/ ) in authenticate process. The package became useless because of inability to authenticate in order to manage client alerts.
Quiet a few users has noticed it as well ( see issue here ).
To make things even funnier, Google algorithms sometimes let you in w/o CAPTCHA, so there is no golden rule where the form with an image characters to re-type will appear.
- What was the solution?
Well, I added support for CAPTCHA, so user ( while in an authentication process ) has to fill CAPTCHA. So, whenever you call
api.sync ( and you are not authenticated yet ), you will be prompted with a message, requiring you to fill in CAPTCHA via command line:
A link ( https://accounts.google.com/Captcha?v=2&ctoken=... ) includes an image with CAPTCHA. You need to display it in a web browser, and re-type in the command line.
Finally, authentication process completes, so you can use a package to create / modify or remove your alerts.
But wait... do I have to re-type CAPTCHA each time I want to authenticate? It makes a package useless...
That is why another way to authenticate has been introduced some time ago. So called
cookies based authentiaction. You can generate cookies:
and then use it (
cookies string ) in this way:
You can store your
cookies somewhere, and reuse it later, when you want to authenticate. Your
username / password pair is no longer needed. Cookies is the only thing required to interact with an API.
How I did implement this:
First of all, while receiving a HTTP response with a HTML body, we have to find out, whether there is a CAPTCHA form available. A
getCaptchaImageByBody function does the job:
Then, we have to find image url ( using
getCaptchaImageByBody ) and ask client to re-type CAPTCHA:
askUser function manages whole command-line stuff, its implementation is available here:
Finally, we can re-send a form with CAPTCHA included. And we are done!
README.md has been also updated to give an API users brief summary, how does the thing work now: