https://gmailusername:pass...@gmail.google.com/gmail/feed/atom/
the above is the url for the aggregators to get the mail headers for
gmail account
if u directly give the url in the browser ,it ask for the user name and
password and display the following xml in the browser .
.______________________________________________________________________________________
<feed version="0.3">
<title>Gmail - Inbox for vsub...@gmail.com</title>
<tagline>New messages in your Gmail Inbox</tagline>
<fullcount>2</fullcount>
<link rel="alternate" href="http://mail.google.com/mail"
type="text/html"/>
<modified>2006-09-13T11:18:20Z</modified>
−
<entry>
<title>Google Alert - IT</title>
−
<summary>
Google Alert for: IT Kicking it back into gear Boston Globe - United
States ... MIAA Division 1 …
</summary>
<link rel="alternate"
href="http://mail.google.com/mail?account_id=vsubram2%40gmail.com&message_id=10da6e10d213e511&view=conv&extsrc=atom"
type="text/html"/>
<modified>2006-09-13T11:12:49Z</modified>
<issued>2006-09-13T11:12:49Z</issued>
<id>tag:gmail.google.com,2004:1214404068052821265</id>
−
<author>
<name>Google Alerts</name>
<email>googlealer...@google.com</email>
</author>
</entry>
−
<entry>
<title>Saying 'I Love You'</title>
−
<summary>
Saying 'I Love You'.............in your own special way. This
guy, a Shanghai university …
</summary>
<link rel="alternate"
href="http://mail.google.com/mail?account_id=vsubram2%40gmail.com&message_id=10da6c5f65a4d2e9&view=conv&extsrc=atom"
type="text/html"/>
<modified>2006-09-13T10:43:14Z</modified>
<issued>2006-09-13T10:43:14Z</issued>
<id>tag:gmail.google.com,2004:1214402206512763625</id>
−
<author>
<name>dipej.neelapareddy</name>
<email>dipej.nee...@wipro.com</email>
</author>
</entry>
</feed>
___________________________________________________________________________________________
my concern is ,i am trying to hit the same url
https://gmailusername:pass...@gmail.google.com/gmail/feed/atom/
thru java url,urlconnection but i dont know how to give the password
and username thru code.
my another question on the above is ,how the aggregator gives the
username and password and why it is required since those are already
incorporated in the user name and the password.
coming to this http://code.google.com/apis/gdatal ,it is for blogger
similarly one more api is provided by gmail for it calender google
service,is there any api's provided for google's gmail service,that i
want to get the mail headers of my unread mails alone and not any other
detail.
I tried the following thru gdata api
URL feedUrlForMail = new URL("
https://gmailusername:pass...@gmail.google.com/gmail/feed/atom/");
String mailServiceName="mail";
GoogleService myService = new GoogleService(mailServiceName,
"exampleCo-exampleApp-1");
myService.setUserCredentials("gmailusername", "password");
Feed myFeed = myService.getFeed(feedUrlForMail, Feed.class);
I am getting the following:
The url to be posted [added in the GDATA
Source]https://www.google.com/accounts/ClientLogin
The content of the URL Posted
service=mail&Passwd=password&Email=gmailusername&accountType=HOSTED_OR_GOOGLE&source=exampleCo-exampleApp-1
In Http_Ok
Got the input stream after launching the url with the parameters [added
in GDATA]
com.google.gdata.util.AuthenticationException: Unauthorized
at
com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:480)
at
com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:458)
at
com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:452)
at
com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:430)
at
com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:441)
at com.google.gdata.client.Service.getFeed(Service.java:458)Service
Exception while getting the feed
at
com.google.gdata.client.GoogleService.getFeed(GoogleService.java:677)
at com.google.gdata.client.Service.getFeed(Service.java:497)
at Headers.readCalendar(Headers.java:33)
at Headers.main(Headers.java:58)
Exception in thread "main" java.lang.NullPointerException
at Headers.main(Headers.java:59)
Please help on this .
However, you can read the feed using a simple Java program. When the
username/password is specified in the URL as in
https://username:password@... the credentials are communicated using a
Basic Authentication header to the server. You can read more about it
here: http://rfc.net/rfc2617.html
The below program gets you started but is not complete. It uses a
Base64 encoder available with the GData Java client download.
String username = "foo";
String password = "bar";
URL requestUrl = new
requestUrl("https://mail.google.com/feed/atom");
HttpURLConnection uc = (HttpURLConnection)
requestUrl.openConnection();
// Encode the user ID and password.
byte[] inputBytes = (username + ":" + password).getBytes();
String b64UserPass =
com.google.gdata.util.common.util.Base64.encode(inputBytes);
httpConn.setRequestProperty("Authorization", "Basic " +
b64UserPass);
// Connect and read response code.
httpConn.connect();
int responseCode = httpConn.getResponseCode();
Hope this helps,
sanjay