The first two articlesArticle
Google Reader API: http://www.cnblogs.com/mybear/archive/2011/02/18/1957704.html
Googlereader user login verification principle: http://www.cnblogs.com/mybear/archive/2011/02/18/1957769.html
I believe you have some knowledge about googlereader API. The following describes how to implement googlereader user login verification C #.
1. Create an httpwebrequest
Private Httpwebrequest createrequest ( String URL)
{
Httpwebrequest webrequest = Webrequest. Create (URL) As Httpwebrequest;
Iwebproxy defaultparoxy = Httpwebrequest. getsystemwebproxy ();
Webrequest. Proxy = Defaultparoxy;
Webrequest. useragent = " Googlereader for Windows/ " + Assembly. getexecutingassembly (). getname (). version;
Webrequest. cookiecontainer = _ Cookiecontainer;
Webrequest. servicepoint. expect100continue = False ;
Webrequest. Timeout = 20000 ;
If (_ Isloginin)
Webrequest. headers. Add ( " Authorization " , " Googlelogin auth = " + _ Loginauth [ 2 ]. Split ( ' = ' )[ 1 ]);
Return Webrequest;
}
2. Use httppost to pass Login Parameters
Private String Postgooglelogin (httpwebrequest webrequest, String Querystring)
{
String Responsestring = String . Empty;
Webrequest. contenttype = " Application/X-WWW-form-urlencoded " ;
Webrequest. Method = " Post " ;
Byte [] Querydata = Encoding. utf8.getbytes (querystring );
Webrequest. contentlength = Querydata. length;
Try
{
Using (Stream stream = Webrequest. getrequeststream ())
{
Stream. Write (querydata, 0 , Querydata. Length );
Stream. Close ();
Responsestring = Getresponsestring (webrequest );
}
}
Catch (Exception ex)
{
Loginerror + = Ex. tostring () + " \ R \ n " ;
}
Return Responsestring;
}
3. Pass the user name and password for login
Public Void Googlelogin ( String Email, String Password)
{
String Sid_id = String . Empty;
String Responsedata = String . Empty;
List < Parameter > Queryparams = New List < Parameter > ();
Queryparams. Add ( New Parameter ( " Service " , " Reader " ));
Queryparams. Add ( New Parameter ( " Email " , Uri. escapedatastring (email )));
Queryparams. Add ( New Parameter ( " Passwd " , Uri. escapedatastring (password )));
Queryparams. Add ( New Parameter ( " Source " , " Mobile newspaper/0.1 " ));
Queryparams. Add ( New Parameter ( " Continue " , " Http://www.google.com " ));
Httpwebrequest webrequest = Createrequest ( " Https://www.google.com/accounts/ClientLogin " );
Responsedata = Postgooglelogin (webrequest, httputil. getqueryparamters (queryparams ));
String Pattern = " SID = (.*) " ;
RegEx Reg = New RegEx (pattern, regexoptions. ignorecase );
If (Reg. ismatch (responsedata ))
{
_ Isloginin = True ;
_ Loginauth = Responsedata. Split ( ' \ N ' );
Sid_id = Reg. Match (responsedata). Groups [ 1 ]. Value;
_ Cookiecontainer. Add ( New Cookie ( " Sid " , Sid_id, " / " , " .Google.com " ));
}
}
So far, Google user login verification is complete! We can create a client RSS subscriber Based on the APIS provided by googlereader!
For example, we want to obtain 20 articles that have been read: You can use httpget to access: http://www.google.com/reader/atom/user/[user id]/State/COM. Google/read
[User id] "-" can be used to represent the current login user. The returned records are in XML format: