I'm trying to write a program that requires me to log in to my Google
Account via Java, however, after playing around with HttpURLConnection
and such it's still not working. Has anyone done this or know where I
can find info on it?
First, depending on what you need to do, there may be
a Google API providing you a clean abstraction, removing
the need to hack with HttpURLConnection.
Quite some time ago I wrote some program to automagically
check Usenet's archives through groups.google.com. Google
was not providing any API for groups.google.gom at that
time (I don't know if they do know).
To make it work, I had to fake the headers. I think
it is especially forbidden by Google to do so, so you may
end up doing something illegal.
Here's a sample of a fake User-Agent header that I must
have grabbed on the net (I don't remember, but it looks
like a "german Windows" Firefox header while I'm not
german and... using Linux since years
My program is still working fine today with that fake User-Agent:
final URLConnection urlCon = url.openConnection();
urlCon.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U;
Windows NT 5.1; de-DE; rv:1.6) Gecko/20040206 Firefox/0.8");
Now, I never tried to actually log into Google using
a Google account.
They may have some protection measure preventing this.
If Yahoo! suspect that you're using a "robot" for example, they'll
present you a nice "captcha". Google /might/ be doing the same
if they think they're detecting a robot (I don't say to do, but they
very well could, just like Yahoo!). Which is why my program used
some randomization/delays/etc. to make it like it wasn't a robot.
It remind me of this quote:
A program designed for inputs from people is usually
stressed beyond breaking point by computer-generated
inputs. -- Dennis Ritchie
But I'm not sure one would really manage to stress Google's
200.000 servers farm
Hope it helps,