Click here to Skip to main content
15,878,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Currently I am using TweetSharp DLL in my project for posting tweets on Twitter with simple text. Now, I want to post a tweet with an image...
I am using this..
C#
Hdn_FullPath.Value = "http://www.domain_name.com/images/Twitter/2015/2/user_icon.png";

#region "Tweet on Twitter"
var service = new TwitterService(DbConnect.ConsumerKey, DbConnect.ConsumerSecret);
service.AuthenticateWith(DbConnect.Token, DbConnect.TokenSecret);
TwitterStatus result;//= service.SendTweet(new SendTweetOptions { Status = txtPost.Text });

string URL_str = Hdn_FullPath.Value;//DbConnect.ShortenUrl(parameters.picture);

using (var stream = new FileStream(URL_str, FileMode.Open))
{
    result = service.SendTweetWithMedia(new SendTweetWithMediaOptions
    {
        Status = txtTweetDetails.Text.Trim(),
        Images = new Dictionary<string, Stream> { { URL_str, stream } }
    });
};

if (result == null)
    throw new NotImplementedException();
#endregion

But in this case, it will return an error at line 48 -
URI formats are not supported.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: URI formats are not supported.

C#
Line 46:         string URL_str = Hdn_FullPath.Value;//DbConnect.ShortenUrl(parameters.picture);
Line 47: 
Line 48:         using (var stream = new FileStream(URL_str, FileMode.Open))
Line 49:         {
Line 50:             result = service.SendTweetWithMedia(new SendTweetWithMediaOptions
Posted
Updated 21-Feb-15 20:12pm
v2

Did you try to go to the library documents[^], and look for the example yourself? If the API supports such function, developer already has shared the method and function to perform the action.

C#
service.SendTweetWithMedia(new SendTweetWithMediaOptions 
                          { 
                               Status = "message", 
                               Images = dictionary 
                          });
 
Share this answer
 
Comments
Er. Ajay Chauhan 22-Feb-15 2:14am    
I tried this one but got an error... see edited question again for more details...
Afzaal Ahmad Zeeshan 22-Feb-15 3:25am    
The error says that the URI you're passing is not allowed. Make sure it is a string, containing the link to the media.
by using
C#
var stream1 = new FileStream(DbConnect.GetPhysicalPath + "\\Images\\Twitter\\2015\\2\\DSCN5670.jpg", FileMode.Open, FileAccess.Read);
 
Share this answer
 
v4

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