Determining whether users are logged into Twitter

John Karahalis
Feb 27, 2015 · 1 min read

Update: This technique no longer works because the Twitter favicon is no longer hosted from the twitter.com domain and the ?redirect_after_login query parameter only works with resources on the twitter.com domain.

In Detect if visitors are logged into Twitter, Facebook or Google+, Tom Anthony explains how to determine what social networks your users are logged into. The approach Tom recommends still works today, but the Twitter code needs to be modified to work as expected.

Tom’s technique involves using a special URL to conditionally load an asset from Twitter if the user is logged in. The asset used in his example no longer exists, however, and most other Twitter assets are now served from a CDN. The conditionally-loaded asset needs to be on the same domain as that special URL (twitter.com) so CDN-hosted assets won’t do.

Thankfully, there is one asset we can still use: the Twitter favicon. This is one of the only assets not served from their CDN and, as a result, one of the only assets that can be conditionally loaded to infer whether the user is logged in.

Change a few characters and you’re good to go. This example uses JavaScript exclusively, but it can be modified to use an img element as Tom does.

Of course, this should be done responsibly. When we used this technique to conduct research on MDN, we told users what was happening. If you use this code, it’s probably not a bad idea to do the same.

Originally published at blog.openjck.com on February 27, 2015.

Reflections

Thoughts on software development

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store