public static OAuth2Token GetToken(string consumerKey, string consumerSecret, ConnectionOptions options = null)
{
if (options == null) options = new ConnectionOptions();
try
{
var token = from x in Request.HttpPost(
GetAccessTokenUrl(options),
new Dictionary<string, object>() { { "grant_type", "client_credentials" } }, // At this time, only client_credentials is allowed.
CreateCredentials(consumerKey, consumerSecret),
options).Use()
from y in new StreamReader(x.GetResponseStream()).Use()
select (string)JObject.Parse(y.ReadToEnd())["access_token"];
var t = OAuth2Token.Create(consumerKey, consumerSecret, token);
t.ConnectionOptions = options;
return t;
}
catch(WebException ex)
{
var tex = TwitterException.Create(ex);
if(tex != null)
throw tex;
throw;
}
}