c# How to login to Google Reader

652 views Asked by At

I'm looking for a code fragment that will show me how to get an SID for Google Reader in C#. Anyone know of such a beast?

2

There are 2 answers

1
Den On

You will have to deal with manual HTTP manipulations and cookies for this. A pretty decent explanation is available on this page. If you worked with HTTP requests in C#, it shouldn't be a problem to pick up the methods described there.

0
Oleks On

It's quite easy. First you should perform a GET request to https://www.google.com/accounts/ClientLogin page with your login and password (don't forget to url encode them). And then just parse response (there will be several parameters divided by a new line character \n) to get SID. Here is a simplest example (no error handling):

var url = string.Format("https://www.google.com/accounts/ClientLogin?service=reader&Email={0}&Passwd={1}",
    HttpUtility.UrlEncode(email),
    HttpUtility.UrlEncode(password)
);
var web = new WebClient();
web.DownloadStringCompleted += (sender, e) =>
{
    var sid = e.Result.Split('\n')
        .First(s => s.StartsWith("SID="))
        .Substring(4);
};
web.DownloadStringAsync(new Uri(url));

But you could make this code more elegant by using AsyncCTP.