How would you mange twitter accounts?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
imac
Forum Newbie
Posts: 6
Joined: Wed Jan 11, 2012 12:57 pm

How would you mange twitter accounts?

Post by imac »

Hello guys

I know this is a very general question and maybe a bit out of topic... but i dont know where can i ask this:

Twitter users can login and post comments on my site, as well as new posts.
Now, i am storing the user ID on my comments table on the database. I was wondering what is the best practice to get users avatar and show it anywhere.
I guess i will have to store also the username as it is used to get the twitter profile picture if i use this code:

<?php
$username = "twitter"; // <-- You did not use quotes here?! Typo?
$xml = simplexml_load_file("http://twitter.com/users/".$username.".xml");
echo $xml->profile_image_url; // <-- No $xml->user here!
?>

But if i have to show, let's say, 20/30 avatars on one same page, do you think there will be a big delay getting all of them?

How would you do it?
There are many pages and systems with have to deal with same problems such as pinterest.com, or liveFyre comment system, disqus... and i was wondering how they do it. What's the best practice for it.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: How would you mange twitter accounts?

Post by social_experiment »

imac wrote:But if i have to show, let's say, 20/30 avatars on one same page, do you think there will be a big delay getting all of them?
Probably; since the content is not on a local server (the same one as where your website is hosted) they have to be retrieved, which takes time. Even if it is just a few seconds.

I would stick with the solution you are currently using; you don't have access to the profile photos and you don't know who is going to post on the site so you can't store images; You could limit the amount of avatars per page if it is really slowing down the page loading times
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: How would you mange twitter accounts?

Post by tr0gd0rr »

Twitter has a direct URL you can use to display the avatar:

Code: Select all

<img src="http://api.twitter.com/1/users/profile_image?screen_name=twitter&size=bigger" width="73" height="73" alt="" />
Valid sizes include bigger, normal, mini, and original. You can use http or https. Full Twitter documentation. The docs claim that it is rate limited, but I have been testing over the last few weeks and it does not count against your limits. Try it yourself then check your rate limit status: https://api.twitter.com/1/account/rate_limit_status.json
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: How would you mange twitter accounts?

Post by tr0gd0rr »

One thing I did discover that you should be aware of: Sometimes you will get a 403 instead of an image and it will display a blank in the browser. A 403 will happen when:

1) You request an original size of a person without an avatar (i.e. will display an egg icon for bigger, normal, and mini). See this bug report where Twitter says they won't fix that behavior. Again, that 403 will only happen on original. For bigger, normal, and mini, you will see an egg icon.

2) There is an error like the account being suspended. Example

If you need to display something instead of the 403, you could set a background image using css or add a JavaScript onerror handler.
Post Reply