Loose Lips...

Updated on Saturday, October 1, 2022

Space and multibyte character encoding for posting to Twitter using OAuth

Updated on Sunday, April 9, 2023

I've spent the last day learning how to use OAuth and XAuth to post to Twitter. There are rumblings that Twitter will start to phase out basic authentication later this year, and more importantly you can only get the nice “via...” attribution if you use OAuth (for new apps, old ones are grandfathered in).

I coded up my own OAuth implementation, referring to Twitter Development: The OAuth Specification on Wrox and the OAuthBase.cs class from the oauth project on Google Code. Both are great references, but both fail with multibyte characters. The problem is that each byte needs to be separately escaped. OAuthBase.cs encodes characters as ints rather than breaking out the bytes and the Wrox article incorrectly suggests using Uri.EscapeDataString().

Here's a method to correctly encode parameters for OAuth:

NoEncode chars is a list of the permitted characters:

An impact of this encoding is that spaces must be encoded as %20 rather than plus. I was worried that each space would end up counting as three characters towards the 140 character limit. I tested this and it isn't true, so use HttpUtility.UrlEncode() to calculate the number of characters in the post OAuthUrlEncode() or similar to actually encode post parameter.

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: Space and multibyte character encoding for posting to Twitter using OAuth #code #twitter #oauth #xauth How to encode spaces and multibyte characters when posting to Twitter via OAuth / XAuth. )

The Perfect Twitter Client

Updated on Sunday, November 6, 2022

I started using bDule today after reading about it on Techcrunch. It seems to be very nearly the perfect twitter client for me - decent multi-account support, Facebook integration and reasonably snappy. Also, and this is really important for me, it's not oppressively black.

The group feature isn't quite there yet, it doesn't list all my friends and there's no way to edit a group after you create it. There's also no spell checker and getting the right layout is unnecessarily awkward. It's still in alpha so there's good reason to hope that these problems will be addressed soon.

I wonder where the name comes from. It makes me think of a certain casual game where you swap gemstones around until you're ready to chew your eyeballs out. I'm the last person to talk about puzzling software names though.

bDule is WPF/.NET3.5 so only runs on Windows XP or better. It also seems to suffer from the same creeping memory usage that plagues other desktop Twitter clients. I really wish someone would start offloading the stream into a database. I've got nearly frustrated enough with this to write my own Twitter client a couple of times, but it's not exactly an uncrowded market.

If you're a Windows tweeter give bDule a try.

Add your comment...

Related Posts

(All Marketing Posts)