CoreTweet.OAuth2.GetToken C# (CSharp) Method

GetToken() public static method

Gets the OAuth 2 Bearer Token.
public static GetToken ( string consumerKey, string consumerSecret, CoreTweet.ConnectionOptions options = null ) : OAuth2Token
consumerKey string The consumer key.
consumerSecret string The consumer secret.
options CoreTweet.ConnectionOptions The connection options for the request.
return OAuth2Token
        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;
            }
        }