开发者

c# How to login to Google Reader

开发者 https://www.devze.com 2023-02-11 11:55 出处:网络
I\'m looking for a code fragment that will show me how to get an SID for Google Reader in C#.Anyone k开发者_JAVA技巧now of such a beast?It\'s quite easy. First you should perform a GET request to http

I'm looking for a code fragment that will show me how to get an SID for Google Reader in C#. Anyone k开发者_JAVA技巧now of such a beast?


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消