static HttpWebRequest FetchAccessToken(httpMethod method, string oauth_consumer_key, string oauth_consumer_secret, string oauth_token, string oauth_verifier) { string postData = "oauth_verifier=" + oauth_verifier; string AccessTokenURL = string.Format("{0}?{1}", ACCESS_TOKEN, postData); string OAuthHeader = OAuthUtility.GetAuthorizationHeaderForPost_OR_QueryParameterForGET(new Uri(AccessTokenURL), callbackUrl, method.ToString(), oauth_consumer_key, oauth_consumer_secret, oauth_token, "", out AccessTokenURL); if (method == httpMethod.GET) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(AccessTokenURL + "?" + OAuthHeader); request.Method = method.ToString(); return(request); } else if (method == httpMethod.POST) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(AccessTokenURL); request.Method = method.ToString(); request.Headers["Authorization"] = OAuthHeader; byte[] array = Encoding.ASCII.GetBytes(postData); request.GetRequestStream().Write(array, 0, array.Length); return(request); } else { return(null); } }
public void PostTwitsOnBehalfOf(string oauth_access_token, string oauth_token_secret, string postData) { HttpWebRequest request = OAuthHelper.PostTwits(oauth_consumer_key, oauth_consumer_secret, oauth_access_token, oauth_token_secret, postData); string result = OAuthHelper.getResponce(request); Dictionary <string, string> dcResult = OAuthUtility.GetQueryParameters(result); if (dcResult["status"] != "200") { this.oauth_error = result; } }
public void LoginWithTwitter() { HttpWebRequest request = FetchRequestToken(httpMethod.POST, oauth_consumer_key, oauth_consumer_secret); string result = getResponce(request); Dictionary <string, string> resultData = OAuthUtility.GetQueryParameters(result); if (resultData.Keys.Contains("oauth_token")) { this.oauth_request_token = resultData["oauth_token"]; } else { this.oauth_error = result; } }
public static HttpWebRequest GetUsers(string oauth_consumer_key, string oauth_consumer_secret, string oauth_access_token, string oauth_token_secret, string username) { username = string.Format("q={0}&page=1&count=3", username); string updateStatusURL = "https://api.twitter.com/1.1/users/search.json?" + username; string outUrl; string OAuthHeaderPOST = OAuthUtility.GetAuthorizationHeaderForPost_OR_QueryParameterForGET(new Uri(updateStatusURL), callbackUrl, httpMethod.GET.ToString(), oauth_consumer_key, oauth_consumer_secret, oauth_access_token, oauth_token_secret, out outUrl); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(updateStatusURL); request.Method = httpMethod.GET.ToString(); request.Headers["Authorization"] = OAuthHeaderPOST; //byte[] array = Encoding.ASCII.GetBytes(postData); //request.GetRequestStream().Write(array, 0, array.Length); return(request); }
public static HttpWebRequest PostTwits(string oauth_consumer_key, string oauth_consumer_secret, string oauth_access_token, string oauth_token_secret, string postData) { postData = "trim_user=true&include_entities=true&status=" + postData; string updateStatusURL = "https://api.twitter.com/1/statuses/update.json?" + postData; string outUrl; string OAuthHeaderPOST = OAuthUtility.GetAuthorizationHeaderForPost_OR_QueryParameterForGET(new Uri(updateStatusURL), callbackUrl, httpMethod.POST.ToString(), oauth_consumer_key, oauth_consumer_secret, oauth_access_token, oauth_token_secret, out outUrl); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(outUrl); request.Method = httpMethod.POST.ToString(); request.Headers["Authorization"] = OAuthHeaderPOST; byte[] array = Encoding.ASCII.GetBytes(postData); request.GetRequestStream().Write(array, 0, array.Length); return(request); }
public void GetUserTwAccessToken(string oauth_token, string oauth_verifier) { HttpWebRequest request = FetchAccessToken(httpMethod.POST, oauth_consumer_key, oauth_consumer_secret, oauth_token, oauth_verifier); string result = getResponce(request); Dictionary <string, string> resultData = OAuthUtility.GetQueryParameters(result); if (resultData.Keys.Contains("oauth_token")) { this.oauth_access_token = resultData["oauth_token"]; this.oauth_access_token_secret = resultData["oauth_token_secret"]; this.user_id = resultData["user_id"]; this.screen_name = resultData["screen_name"]; } else { this.oauth_error = result; } }
static HttpWebRequest FetchRequestToken(httpMethod method, string oauth_consumer_key, string oauth_consumer_secret) { string OutUrl = ""; string OAuthHeader = OAuthUtility.GetAuthorizationHeaderForPost_OR_QueryParameterForGET(new Uri(REQUEST_TOKEN), callbackUrl, method.ToString(), oauth_consumer_key, oauth_consumer_secret, "", "", out OutUrl); if (method == httpMethod.GET) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(OutUrl + "?" + OAuthHeader); request.Method = method.ToString(); return(request); } else if (method == httpMethod.POST) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(OutUrl); request.Method = method.ToString(); request.Headers["Authorization"] = OAuthHeader; return(request); } else { return(null); } }