Googlereader user login verification C # specific implementation

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.