Skip to content

Commit

Permalink
#3 #4 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
syuilo committed May 16, 2014
1 parent 1df7d14 commit 7c75f0f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 27 deletions.
4 changes: 2 additions & 2 deletions HTTP/Twitter/OAuth/OAuthCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static string GenerateSignature(
Console.WriteLine("-\t-\t## シグネチャを生成します");
#endif

SortedDictionary<string, string> Parameters = new SortedDictionary<string, string>();
var Parameters = new SortedDictionary<string, string>();

Parameters.Add("oauth_consumer_key", Context.ConsumerKey);
Parameters.Add("oauth_nonce", Nonce);
Expand Down Expand Up @@ -188,7 +188,7 @@ public static string UrlEncode(string value, Encoding encode)
{
string unreservedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~";

StringBuilder result = new StringBuilder();
var result = new StringBuilder();
byte[] data = encode.GetBytes(value);
int len = data.Length;

Expand Down
4 changes: 2 additions & 2 deletions HTTP/TwitterRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public async Task<string> Request()
}

// リクエストの作成
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(url);
var Request = (HttpWebRequest)WebRequest.Create(url);

if (this.Proxy != null)
Request.Proxy = new WebProxy(this.Proxy);
Expand All @@ -146,7 +146,7 @@ public async Task<string> Request()
try
{
// リクエストの送信
HttpWebResponse Response = (HttpWebResponse)await Request.GetResponseAsync();
var Response = (HttpWebResponse)await Request.GetResponseAsync();

using (StreamReader ResponseDataStream = new StreamReader(Response.GetResponseStream()))
{
Expand Down
1 change: 1 addition & 0 deletions Twitch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
<Compile Include="Utility\Twitter\Authorize.cs" />
<Compile Include="Utility\Twitter\Image.cs" />
<Compile Include="Vermillion\Utility\RandomString.cs" />
<Compile Include="Vermillion\Utility\RandomText.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="favicon.ico">
Expand Down
56 changes: 33 additions & 23 deletions Utility/Twitter/Authorize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,40 +116,50 @@ public void ShowAuthorizeBrowser()
public async Task<TwitterContext> GetAccessTokenFromScreenNameAndPassword(
string ScreenName, string Password)
{
System.Net.WebClient wc = new System.Net.WebClient();
string sorce = wc.DownloadString("https://twitter.com");
wc.Dispose();
if (this.OAuthToken == null)
throw new NullReferenceException("リクエスト トークンが設定されていません。");

try
{
var wc = new System.Net.WebClient();
string sorce = wc.DownloadString("https://twitter.com");
wc.Dispose();

Regex reg = new Regex("<input type=\"hidden\" name=\"authenticity_token\" value=\"(?<token>.*?)\">",
RegexOptions.IgnoreCase | RegexOptions.Singleline);
Regex reg = new Regex("<input type=\"hidden\" name=\"authenticity_token\" value=\"(?<token>.*?)\">",
RegexOptions.IgnoreCase | RegexOptions.Singleline);

Match m = reg.Match(sorce);
Console.WriteLine("authenticity_token: " + m.Groups["token"].Value);
Match m = reg.Match(sorce);
System.Diagnostics.Debug.WriteLine("authenticity_token: " + m.Groups["token"].Value);

string url = "https://api.twitter.com/oauth/authorize";
string url = "https://api.twitter.com/oauth/authorize";

wc = new System.Net.WebClient();
wc = new System.Net.WebClient();

System.Collections.Specialized.NameValueCollection ps =
new System.Collections.Specialized.NameValueCollection();
System.Collections.Specialized.NameValueCollection ps =
new System.Collections.Specialized.NameValueCollection();

ps.Add("authenticity_token", m.Groups["token"].Value);
ps.Add("oauth_token", OAuthToken);
ps.Add("session[username_or_email]", ScreenName);
ps.Add("session[password]", Password);
ps.Add("authenticity_token", m.Groups["token"].Value);
ps.Add("oauth_token", OAuthToken);
ps.Add("session[username_or_email]", ScreenName);
ps.Add("session[password]", Password);

byte[] resData = wc.UploadValues(url, ps);
wc.Dispose();
byte[] resData = wc.UploadValues(url, ps);
wc.Dispose();

string resText = System.Text.Encoding.UTF8.GetString(resData);
string resText = System.Text.Encoding.UTF8.GetString(resData);

reg = new Regex("<code>(?<pin>.*?)</code>",
RegexOptions.IgnoreCase | RegexOptions.Singleline);
reg = new Regex("<code>(?<pin>.*?)</code>",
RegexOptions.IgnoreCase | RegexOptions.Singleline);

m = reg.Match(resText);
Console.WriteLine("pin: " + m.Groups["pin"].Value);
m = reg.Match(resText);
System.Diagnostics.Debug.WriteLine("pin: " + m.Groups["pin"].Value);

return await GetAccessTokenFromPinCode(m.Groups["pin"].Value);
return await GetAccessTokenFromPinCode(m.Groups["pin"].Value);
}
catch (Exception e)
{
return null;
}
}

/// <summary>
Expand Down
12 changes: 12 additions & 0 deletions Vermillion/Utility/RandomText.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Twitch.Vermillion.Utility
{
public static class RandomText
{
}
}

0 comments on commit 7c75f0f

Please sign in to comment.