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");
}
}
}

Ankush RathodPosted Jul 18, 2017, 9:22 AM
ConsumerKey, ConsumerSecret, requestToken and pin parameters have proper values. But, I'm getting an error : Twitterizer.OAuthUtility.GetRequestToken() “Value cannot be null. Parameter name: String”.
Rajesh JaiswalPosted Jan 19, 2016, 1:18 AM
Getting ERROR: {"errors":[{"message":"The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.","code":64}]}
Ishelf BookPosted Sep 14, 2015, 2:09 AM
i am suing same steps in my c# web application, But i am getting bellow error. please reply me asap its urgently. thanks. {"errors":[{"message":"The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.","code":64}]}
Suraj KumarPosted Jul 7, 2015, 4:00 AM
An exception of type 'System.IO.FileLoadException' occurred in Twitterizer2.dll but was not handled in user code Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=4.0.5.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Suraj KumarPosted Jul 7, 2015, 3:59 AM
I am getting Exception in the line: TwitterResponse<TwitterStatus> response = TwitterStatus.UpdateWithMedia(accesstoken, "img", photo);