Aaron
Aaron

Reputation: 1061

Should HtmlEncode be used when updating twitter status with Tweetsharp?

I am using tweetsharp to send tweets.

var response = _twitter.AuthenticateWith(item.TwitterToken, item.TwitterSecret)
    .Statuses().Update(HttpUtility.HtmlEncode(item.Tweet)).AsXml().Request().Response;

As you may have noticed, above I am HtmlEncoding the message this can cause the message to go over 140 chars? Is encoding the message this way necessary? Does tweetsharp or twitter recommend sending messages without encoding first?

Upvotes: 2

Views: 749

Answers (2)

Jason Diller
Jason Diller

Reputation: 3368

TweetSharp will handle all of the encoding for you. Just pass it the string you want to post.

Upvotes: 1

Kyle Rosendo
Kyle Rosendo

Reputation: 25277

From here:

The Twitter API supports UTF-8 encoding. Please note that angle brackets ("<" and ">") are entity-encoded to prevent Cross-Site Scripting attacks for web-embedded consumers of JSON API output. The resulting encoded entities do count towards the 140 character limit. When requesting XML, the response is UTF-8 encoded. Symbols and characters outside of the standard ASCII range may be translated to HTML entities.

This says to me that you should indeed make sure that your output is encoded (not necessarily HTML encoded) to UTF-8. Have you tried to UTF-8 encode and then submit, then look at the output of "special" characters?

Upvotes: 1

Related Questions