using System;<br> using OAuth;<br> using System.Net;<br> using System.IO;<br> using System.Text; <br><br> * This source code was highlighted with Source Code Highlighter .
// : <br> Uri uri = new Uri ( "http://api.twitter.com/oauth/request_token" );<br> string consumerKey = " consumerKey" ;<br> string consumerSecret = " consumerSecret" ;<br> // OAuthBase <br>OAuthBase oAuth = new OAuthBase();<br> // <br> string timeStamp = oAuth.GenerateTimeStamp();<br> string nonce = oAuth.GenerateNonce();<br> string normUri;<br> string normParams;<br> string sig = oAuth.GenerateSignature(uri, consumerKey, consumerSecret, string .Empty, string .Empty, "GET" , timeStamp, nonce, OAuth.OAuthBase.SignatureTypes.HMACSHA1, out normUri, out normParams);<br> // <br> string request_url = <br> "http://api.twitter.com/oauth/request_token" + "?" +<br> "oauth_consumer_key=" + consumerKey + "&" +<br> "oauth_signature_method=" + "HMAC-SHA1" + "&" +<br> "oauth_signature=" + sig + "&" +<br> "oauth_timestamp=" + timeStamp + "&" +<br> "oauth_nonce=" + nonce + "&" +<br> "oauth_version=" + "1.0" ;<br> Console .WriteLine( "Req: " + request_url); // <br> Console .WriteLine( "--------------------------------------------------------" );<br> // <br>HttpWebRequest Request = (HttpWebRequest) HttpWebRequest.Create(request_url);<br>HttpWebResponse Response = (HttpWebResponse)Request.GetResponse(); <br>StreamReader Reader = new StreamReader(Response.GetResponseStream(), Encoding .GetEncoding(1251));<br> string outline = Reader.ReadToEnd(); <br> Console .WriteLine( "Out: " + outline);<br> Console .WriteLine( "--------------------------------------------------------" );<br> // <br> char [] delimiterChars = { '&' , '=' };<br> string [] words = outline.Split(delimiterChars);<br> string oauth_token = words[1]; <br> string oauth_token_secret = words[3];<br> string oauth_callback_confirmed = words[5];<br> // <br> Console .WriteLine( "oauth_token = " + oauth_token); <br> Console .WriteLine( "oauth_token_secret = " + oauth_token_secret); <br> Console .WriteLine( "oauth_callback_confirmed = " + oauth_callback_confirmed);<br> Console .WriteLine( "--------------------------------------------------------" ); <br><br> * This source code was highlighted with Source Code Highlighter .
// <br> // PIN <br>request_url = "http://api.twitter.com/oauth/authorize?oauth_token=" + oauth_token;<br> Console .WriteLine( "Req: " + request_url);<br> Console .WriteLine( "--------------------------------------------------------" );<br>System.Diagnostics.Process.Start(request_url); // PIN- <br> Console .Write( "Enter PIN: " );<br> string oauth_verifier = Console .ReadLine(); // oauth_verifier — PIN-. <br> Console .WriteLine( "--------------------------------------------------------" ); <br><br> * This source code was highlighted with Source Code Highlighter .
// <br>request_url = <br> "http://api.twitter.com/oauth/access_token" + "?" +<br> "oauth_consumer_key=" + consumerKey + "&" +<br> "oauth_token=" + oauth_token + "&" +<br> "oauth_signature_method=" + "HMAC-SHA1" + "&" +<br> "oauth_signature=" + sig + "&" +<br> "oauth_timestamp=" + timeStamp + "&" +<br> "oauth_nonce=" + nonce + "&" +<br> "oauth_version=" + "1.0" + "&" +<br> "oauth_verifier=" + oauth_verifier;<br> Console .WriteLine( "Req: " + request_url);<br> Console .WriteLine( "--------------------------------------------------------" ); <br> // <br>Request = (HttpWebRequest) HttpWebRequest.Create(request_url);<br>Response = (HttpWebResponse)Request.GetResponse(); <br>Reader = new StreamReader(Response.GetResponseStream(), Encoding .GetEncoding(1251));<br>outline = Reader.ReadToEnd(); <br> Console .WriteLine( "Out: " + outline);<br> Console .WriteLine( "--------------------------------------------------------" );<br> // <br>words = outline.Split(delimiterChars);<br>oauth_token = words[1]; <br>oauth_token_secret = words[3];<br> string user_id = words[5];<br> string screen_name = words[7];<br> // <br> Console .WriteLine( "oauth_token = " + oauth_token); <br> Console .WriteLine( "oauth_token_secret = " + oauth_token_secret); <br> Console .WriteLine( "user_id = " + user_id);<br> Console .WriteLine( "screen_name = " + screen_name); <br><br> * This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/103365/
All Articles