Reputation: 7594
I have my own Twitter API and I've received a couple emails about a problem when trying to post a status update with accent marks and other diacritics. I would like to encode these so that the status update still has them.
I know there are ways to remove the diacritic, but I would like to keep it.
I read the Twitter Counting Characters page and noticed that they did talk about encoding the diacritic. I would like to do this in C#. I am just not sure how to do it.
Here was the original bug report for the Twitter API http://code.google.com/p/twitter-api/issues/detail?id=433
I've tried using..
string oldStatus = "con eñe";
string newStatus = oldStatus.Normalize(NormalizationForm.FormD);
I've tried using FormC
, FormKC
, and FormKD
, and I either get the 401 - Unauthorized
error or a Invalid Unicode value in one or more parameters
error.
Any ideas?
Upvotes: 4
Views: 1594
Reputation: 4387
Does this help? I tested the app this is from and it successfully posted my update using the diacritic in your post (and at 140 characters long).
HttpWebRequest request = CreateRequest("https://twitter.com/statuses/update.xml", "POST",
username, password);
string str = HttpUtility.UrlEncode(status);
byte[] buffer = new UTF8Encoding(false, false).GetBytes("status=" + str);
using (Stream stream = request.GetRequestStream())
{
stream.Write(buffer, 0, buffer.Length);
}
request.GetResponse().Close();
Upvotes: 1