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.

And help there quickly came.

That looked good in theory, but I couldn’t make it work in practice non-programmatically, even with the authentication keys. Not to worry, more help was to hand.

Well I don’t particularly python, but I was game to try, though this was starting to turn into a more serious enterprise than the size of the task seemed to warrant.

But then I struck gold – though I nearly missed 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.

Thanks to Simon Dawson, Chris Yiu and Joshua Mouldey

And further thanks to Adrian Short for providing the perfect postscript:

All long help threads should have a sticky globally-editable post at the top saying 'DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far ...'

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.