Using atom feed to read mails in Gmail

I wanted to read my emails from Gmail using an atom feed. Gmail supports it, for the entire procedure you are welcomed to read http://code.google.com/apis/accounts/docs/OAuth2.html however one thing that is missing from the explanation is the final part, i.e. how do I fetch using the access code that I just received.

At the beginning I tried to append ?access_token=YOUR_ACCESS_TOKEN to my oauth address (https://mail.google.com/mail/feed/atom in our case), it didn’t work, I always got 401 access denied.

Guess what, Gmail only supports  the Authorization: Bearer <access_token> header  so your request should be something like

GET /m8/feeds/contacts/default/full HTTP/1.1
Authorization: Bearer YOUR_ACCESS_TOKEN

Hope it will save you some frustration.

5 Comments

Filed under API

5 responses to “Using atom feed to read mails in Gmail

  1. how can you pass “GET /m8/feeds/contacts/default/full HTTP/1.1
    ” by the header? can you give me a sample code of the call?? thanks

    • Did something like that
      Map headers = new HashMap();
      headers.put(“Authorization”, format(“Bearer %s”, “token”));
      HttpConnector localUrl;
      localUrl.addRequestProperty(“Authorization”, String.format(“Bearer %s”, “token”));

  2. suresh

    hi.. In my project i am using atom feed for read mails in Yahoo , can you give a sample code for that..Thank you..

    • Hi Suresh,

      Try this…
      HttpURLConnection localUrl;

      localUrl.setDoOutput(false);
      BufferedReader rd = null;
      try {
      // Get the response
      rd = new BufferedReader(
      new InputStreamReader(localUrl.getInputStream()));
      String line;
      StringBuilder builder = new StringBuilder();
      while ((line = rd.readLine()) != null) {
      builder.append(line);
      }
      returnValue = builder.toString();
      } finally {
      if (rd != null) {
      rd.close();
      }
      }

  3. Even though we don’t see things thhe same way, thanks
    a lot for the post. I want to know what platform this website
    is built on top. Can you let me know? I’m truly
    considering blogging, andd I want to sstart with the best possible
    platform. I truly appreciate this.

Leave a comment