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.
How would you mange twitter accounts?
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: How would you mange twitter accounts?
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.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?
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
Re: How would you mange twitter accounts?
Twitter has a direct URL you can use to display the avatar:
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
Code: Select all
<img src="http://api.twitter.com/1/users/profile_image?screen_name=twitter&size=bigger" width="73" height="73" alt="" />Re: How would you mange twitter accounts?
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.
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.