views:

91

answers:

2

My teacher has given me as an assignment to log into gmail and then send one e-mail or read the list of unread e-mails, but I can't use IMAP/POP3/SMTP or anything that isn't HTTP or HTTPS. I've tried looking for libraries in Ruby/Java to do it but nothing really worked for me.

I tried looking at the gmail source code page but I couldn't really understand what was going on. The page seems to call a post method on a link, but sniffing the packets what I saw was a GET apparently using a session generated using the info I send. So sending it "raw" didn't work either.

I've no idea what to do now.

A: 

After you authenticate with OAuth, you can get unread emails via an atom feed.

URL to hit: https://mail.google.com/mail/feed/atom/[<label>]

You can toy around with this at the Google oauth playground. Get an access token by continually clicking buttons and authenticating, and then hit discover feeds.

If you want a Java OAuth library, signpost is really good. You'll need to read the google documentation on its open authentication scheme. Specifically, you need to pass a scope query parameter when you attempt to authenticate. This is nonstandard, and it will trick you up if you're not looking for it.

If you're confused about OAuth or why its necessary, you may want to check out this resource.

Stefan Kendall
I clicked the buttons on the Google OAuth Playground and then it asked me for my login info. But why use OAuth when it still requests for it? Isn't this useful only if I'm logging in from another site?
master chief
OAuth authenticates your application with Gmail. If you're logged into google docs, for example, you wouldn't want any random program able to steal and use your documents. You have to explicitly authorize programs to use the google web services, of which gmail is one.
Stefan Kendall
Once you have your access token for a particular user and set of web services, though, you're golden until it expires (which it may never).
Stefan Kendall
A: 

Check out httplib2—it has (among other things) Google Account Authentication.

Hank Gay