Archives

Variable randomness

The main point of this post is to remind myself of how to solve a problem in the unlikely event that I encounter it again. If anybody else with the same problem stumbles across it, so much the better.

In these modern times, it is easy to quote a tweet on a wordpress blog post – you just put in its url and a kind of magic happens. Back in the olden days, life wasn’t as easy as that, but there was a third party plug in called Blackberry Pie which performed an equivalent function. It broke with an api change years ago, but I still have a handful of its shortcodes scattered across long ago posts.

Most of them are easy enough to fix – the shortcode includes the full link to a tweet which is easily extracted. But Blackberry Pie was smart enough to cope with just the tweet id, and there is no apparent way of recreating the full tweet url from that, since links always include the twitter username.

So I turned to Twitter itself for help.

Twitter question: given the ID number of a tweet (the long number in the url) but not the account name, is there any way of finding it?

My first thought was that this had missed the point altogether. The link structure

https://twitter.com/Tweet_Maker_User_Name/status/Tweet_ID

still seemed to need me to know what to put in for the placeholder Tweet_Maker_User_Name, which was precisely the problem I had in the first place. But then it occurred to me that perhaps it was a special code which effectively did the job of the api call and that only Tweet_ID needed to be substituted. And so it proved. The link resolved to the full standard url, username and all. Job done.

But I was still a bit curious about the apparently generic username placeholder and wondered whether it was documented. A search produced precisely one result, a Stackoverflow discussion of the question I had started with. One contributor suggested the Tweet_Maker_User_Name approach – and was squashed by another who made the same misjudgement I had. But the final reply gives the answer I had begun to suspect, that the link structure is not so much

https://twitter.com/Tweet_Maker_User_Name/status/Tweet_ID

as

https://twitter.com/any_random_string/status/Tweet_ID

Indeed, even substituting a valid but incorrect username doesn’t cause a problem, the link still resolves to the correct full url, fixing the wrong username as it goes.

Which leaves me with the intriguing twin thoughts that the use of usernames in twitter urls is to help human readers rather than having any technical significance, and that this redundancy appears to be very little known.

And a final serendipitous twist. The Stackoverflow question was posted on 22 May 2009, six years almost to the day before I was looking for the answer. It’s attracted a leisurely eight responses over those six years, the last and most useful of which was posted on 17 May 2015, immaculately timed to be there when I looked for it.