Updated on Wednesday, February 22, 2017

We'd probably be living in a post-scarcity Star Trek / Culture style universe happily working on self-actualization if we didn't have to spend so much time fucking around with OAuth.


(Related: The Secret Diary of a Xamarin Android Developer, Aged 48 1/3; The real reason Americans don't have passports; Methyl L-α-aspartyl-L-fucking-phenylalaninate)

(You might also like: Fitbit on a bike; Autumnal Equinox 2014; Skull Cave)

(All Etc Posts)

Space and multibyte character encoding for posting to Twitter using OAuth

Updated on Saturday, November 2, 2019

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.

(Related: Better related posts with word2vec (C#); Export Google Fit Daily Steps, Weight and Distance to a Google Sheet; Get an email when your security camera sees something new (Apps Script + Cloud Vision))

(You might also like: Finding NPR on Windows Mobile; Elsie Street, west slope of Bernal Heights; McArthur-Burney Falls)

(All Code Posts)

I Thought He Came With You is Robert Ellison's blog.