Post Image with Message in Twitter Tweet in .NET Framework 4.0. Create ASP.NET web application. add default page. add below given code in code behind.

  • Go to tools
  • Select library package manager
  • Select Package Manager console after selecting this below in package manager console select source as nugget official package source and select your project name in default project
  • Execute command
  • Install-Package twitterizer - Version 2.4.1

using Twitterizer;

using System.IO;

protected void Page_Load(object sender, EventArgs e)

{
CheckAuthorization();

}

private void CheckAuthorization()
{

string oauth_consumer_key = "abcdefghijk";
string oauth_consumer_secret = "1234567890w4ew4erere";

if (Request["oauth_token"] == null)

{
OAuthTokenResponse reqToken = OAuthUtility.GetRequestToken(oauth_consumer_key, oauth_consumer_secret, Request.Url.AbsoluteUri);
Response.Redirect(string.Format("http://twitter.com/oauth/authorize?oauth_token={0}", reqToken.Token) );
}

else
{

string requestToken = Request["oauth_token"].ToString();
string pin = Request["oauth_verifier"].ToString();
var tokens = OAuthUtility.GetAccessToken(oauth_consumer_key, oauth_consumer_secret, requestToken, pin);
OAuthTokens accesstoken = new OAuthTokens()
{

AccessToken = tokens.Token,

AccessTokenSecret = tokens.TokenSecret,

ConsumerKey = oauth_consumer_key,

ConsumerSecret = oauth_consumer_secret

};

//~/img/th2.jpg

byte[] photo = File.ReadAllBytes(@"C:\Users\user\Documents\Visual Studio 2012\WebSites\WebSite35\img\Koala.jpg");

TwitterResponse<TwitterStatus> response = TwitterStatus.UpdateWithMedia(accesstoken, "img", photo);
if (response.Result == RequestResult.Success)
{

Response.Write(
"This is YOUR PAGE");
}

else
{

Response.Write(
"Try some other time");
}

}

}

image1.jpg