tweetsharp - How to post Special charater tweet using asp.net API? -
i m using given below code post tweet on twitter. when upload on server special character (!,:,$ etc) tweets not published on twitter. code working fine in local system
string key = ""; string secret = ""; string token=""; string tokensecret=""; try { string localfilename = httpcontext.current.server.mappath("../images/").tostring(); 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> { { "name", stream } } }); } } else // message { var result = service.sendtweet(new sendtweetoptions { status = httputility.urlencode(message) }); } } catch (exception ex) { throw ex; }
the statuses/update_with_media api endpoint deprecated twitter , shouldn't used (https://dev.twitter.com/rest/reference/post/statuses/update_with_media).
tweetsharp has issues using method when tweet contains both 'special character' , image (works fine either, not both). don't know why , haven't been able fix it, it's oauth signature i'm pretty sure.
as solution suggest use tweetmoasharp (a fork of tweetsharp). has been updated support new twitter api's handling media in tweets, , work in situation if use new stuff.
basically upload each media item using new uploadmedia method, , return 'media id'. use normal 'sendtweet' method , provide list of media ids along other status details. twitter attach media tweet when posted, , work when there both special characters , images.
Comments
Post a Comment