Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to tweet to twitter withot using any .dll i have already token,tokensecret etc.
plz suggest me. thnx
Posted
Comments
Mac_Hac 18-Sep-12 2:44am    
i am already connect to twitter and i have already authtoken,tokensecrete,accesstoken,consumerkey,cosumersecretkey
but how to post to twitter because some site using Twitterize .dll but i want to post with a Webrequest.
Mac_Hac 19-Sep-12 1:36am    
I getting an error 401 unautorized in Twitter Post. Plz Help me.


public void PostTweet()
{

string baseUrl = "https://api.twitter.com/1/statuses/update.json";
const string signatureMethod = "HMAC-SHA1";
const string oauthVersion = "1.0";
var timeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1));
string timestamp = ((int)timeSpan.TotalSeconds).ToString();
var nonce = GenerateNonce(timestamp);
var signature = sign;//CreateSignature(requestMethod, baseUrl, consumerKey, consumerSecret, nonce, signatureMethod, timestamp, accessToken, oauthVersion, string.Empty, string.Empty, requestType, status);
var bodyData = "status=" + UrlEncode("Post to ");
var webRequest = (HttpWebRequest)WebRequest.Create(baseUrl);
webRequest.KeepAlive = true;
webRequest.ServicePoint.Expect100Continue = false;
webRequest.Method = HttpMethod.Post;

//Send in as POST

webRequest.Accept = "*/*";
webRequest.UserAgent = "Renicorp.Social";
//webRequest.Headers["Authorization"] = testheader;
webRequest.Headers["Authorization"] = "OAuth " + UrlEncode("oauth_consumer_key") + "=\"" + UrlEncode("P54j3gUio46UJeSsk6DUw") + "\", " +
UrlEncode("oauth_nonce") + "=\"" + UrlEncode(nonce) + "\", " +
UrlEncode("oauth_signature") + "=\"" + UrlEncode(signature) + "\", " +
UrlEncode("oauth_signature_method") + "=\"" + UrlEncode(signatureMethod) + "\", " +
UrlEncode("oauth_timestamp") + "=\"" + UrlEncode(timestamp.ToString()) + "\", " +
UrlEncode("oauth_token") + "=\"" + UrlEncode(testaccesstoken) + "\", " +
UrlEncode("oauth_version") + "=\"" + UrlEncode(oauthVersion) + "\"";
string postData = bodyData;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = byteArray.Length;
using (Stream dataStream = webRequest.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
} //Make the web call and return the response
WebResponse response = webRequest.GetResponse();
var responseBody = string.Empty;
Stream stream = response.GetResponseStream();
if (stream != null)
responseBody = new StreamReader(stream).ReadToEnd();
//return responseBody;
//string url = "http://twitter.com/statuses/update.xml?access_token="+token;
//WebbRequest(Method.POST, url, "message=" + HttpUtility.UrlEncode(msg));

}

1 solution

0. (Prerequisite) Stop being lazy, learn to use Google and write some code yourself or just be lazy and use existing libraries.
1. Visit Twitter's developers site.
2. Learn how oAuth authentication works.
3. Write your own code to do oAuth authentication with Twitter.
4. Learn how to use the Twitter API.
5. Write your own code to communicate with the Twitter API.
6. Realise that you should have just used an existing library because it would have been less work and will be better supported in the future (if you pick a good one).
7. Don't come back asking which one to use...

Ed
 
Share this answer
 
Comments
bbirajdar 18-Sep-12 2:36am    
+5.correct answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900