Search code examples
ruby-on-railsrubytwitter

Twitter profile pictures don't appear in rails app


I'm building a web app using rails. In this site I basically have several profiles, each of them linked to a specific profile picture from twitter.

Instead of install a twitter gem or similar, I just use this line of code:

https://twitter.com/<%= influencer.username %>/profile_image?size=original

It works great, but what I've discovered is that in some devices the browser can't show them. Specially on phones.

Any ideas of why this thing doesn't work? Or, is there another way to do this?

The website (super beta) is: https://influencerlist.io

Thank you!


Solution

  • That’s because on phones, Twitter redirects to mobile.twitter.com, and the image URL is not available on mobile.twitter.com (try this in a browser for yourself). The correct way to obtain the user profile image would be via the Twitter API and querying the user object from /1.1/users/show.json (or, via the users/lookup batch endpoint).