Created
June 23, 2010 07:35
-
-
Save rekkusu/449605 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Key values | |
const string XAuthUsername = "x_auth_username"; | |
const string XAuthPassword = "x_auth_password"; | |
const string XAuthMode = "x_auth_mode"; | |
public bool GetAccessToken(string userName, string password) | |
{ | |
List<KeyValuePair<string, string>> para = new List<KeyValuePair<string, string>>(); | |
para.Add(new KeyValuePair<string, string>(XAuthUsername, userName)); | |
para.Add(new KeyValuePair<string, string>(XAuthPassword, UrlEncode(password, Encoding.Default, true))); | |
para.Add(new KeyValuePair<string, string>(XAuthMode, "client_auth")); | |
var target = CreateUrl(XAuthProviderAccessTokenUrl, RequestMethod.POST, para); | |
try | |
{ | |
var ret = Http.WebConnectDownloadString(new Uri(target), "POST", null); | |
if (ret.Exception != null) | |
throw ret.Exception; | |
if (!ret.Succeeded) | |
{ | |
return false; | |
} | |
var rd = SplitParamDict(ret.Data); | |
if (rd.ContainsKey("oauth_token") && rd.ContainsKey("oauth_token_secret")) | |
{ | |
Token = rd["oauth_token"]; | |
Secret = rd["oauth_token_secret"]; | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
catch (WebException) | |
{ | |
throw; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment