سؤال

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 that using the API is not the best option as it has a rate limit of 150/hour or 350/hour if OAuth is used.

Then i thought about getting it with this little 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 avatars on one same page, maybe there will be a little delay getting all of them.

I also thought about storing them on the database on a users table with the nick and so on. But then... what if the user updates his profile picture? I would still having the old one...

So, what is the best practice for it? There are many pages and systems with have to deal with same problems such as pinterest.com, or liveFyre comment system, disqus...

Thanks

هل كانت مفيدة؟

المحلول

I would say that you need to store the avatar URL generated by twitter and use that without calling the API everytime. Or use this service http://tweetimag.es/

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top