Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I implemented the given below code for tweets in C#. But any special character (',!#@$ etc) is come in the title, tweet is not published on twitter.

What I have tried:

I tried given below code.

C#
using (WebClient client = new WebClient())
               {
                   client.DownloadFile(imagePath, localFilename);
               }
               var service = new TweetSharp.TwitterService(key, secret);
               service.AuthenticateWith(token, tokenSecret);

               // Tweet wtih image
               if (imagePath.Length > 0)
               {
                   using (var stream = new FileStream(localFilename, FileMode.Open))
                   {
                       var result = service.SendTweetWithMedia(new SendTweetWithMediaOptions
                       {
                           Status = message,
                           Images = new Dictionary<string, Stream> { { "nkt", stream } }
                       });
                       Response.Write(result);
                   }
               }
Posted
Updated 26-May-16 1:16am
v2

1 solution

C#
You can install the Microsoft.AspNet.WebApi.Client NuGet package on the client you could directly use the new HttpClient class (which is the new kid on the block) to consume your WebAPI instead of WebClient:
Sample implementation will be like below

Animal a = new Animal();
a.Message = "öçşistltl";
var URI = "http://localhost/Values/DoSomething";
using (var client = new HttpClient())
{
    client
        .PostAsync<Animal>(URI, a, new JsonMediaTypeFormatter())
        .ContinueWith(x => x.Result.Content.ReadAsStringAsync().ContinueWith(y =>
        {
            Console.WriteLine(y.Result);
        }))
        .Wait();
}
 
Share this 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