Skip to content

Instantly share code, notes, and snippets.

@rekkusu
Created June 23, 2010 07:35
Show Gist options
  • Save rekkusu/449605 to your computer and use it in GitHub Desktop.
Save rekkusu/449605 to your computer and use it in GitHub Desktop.
// 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