If you haven’t already, you should really check out Stack Overflow; it’s a community driven programming questions/answers site where people earn reputation and badges for contributing.
I wanted to put an XBox Live style "gamertag" on my blog with a link to my Stack Overflow profile and my current "reputation". I couldn’t find anything out there so I thought I’d dig up some Widget sample code and steal adapt it to display what I wanted.
There doesn’t seem to be any API for getting the information I wanted, so it uses a basic screen scrape, which may well stop working if they tweak the pages and may well not work for everyone’s profile page, but it works for mine and that’s all I care about 😉 Seriously though, if anyone else wants to use it and has problems, feel free to drop me a line and I’ll take a look at it. I’m no PHP expert either, so if anyone wants to tell me if my code sucks horribly, feel free 😀
You should be able to see the widget over on the right, and you can grab the widget itself below. Once it’s installed you need to configure it to give it your user number (26507 in my case) and your email address (so it can pull out your Gravatar). The email address isn’t used for anything other than hashing for the Gravatar, but you can read the source if you don’t believe me 🙂
Update: I’ve made a few changes in response to a few comments, and also removed the little place holder and badges in there. It takes into account badges that have been awarded multiple times, so it *should* be the same as your SO page 🙂
Update2: Thanks to Ólafur Waage for providing an update to add a clear div after the widget and to run the name through htmlentities to handle names with “funky characters” 🙂
Update3: Version 2.0.0 is now available on the WordPress plugin page. It has a simple cachine system and also now pulls its data from the Stack Overflow JSON feed, rather than using screen scraping. More info in the new post: Updated: Stack Overflow WordPress Widget.
New screenshot and download below:
I’m amazed that SO does not provide some kind of API for this. It would be really need to widget-ize your user summary (such as you have) as well as being able to pull in the last few questions that you have asked.
This would enable you to push the questions to your blog, which hopefully gets more people involved with SO.
[…] Stack Overflow “GamerTag” Style Reputation Widget […]
[…] Stack Overflow “GamerTag” Style Reputation Widget […]
[…] Stack Overflow “GamerTag” Style Reputation Widget […]
[…] Stack Overflow “GamerTag” Style Reputation Widget :XBox Live “GameTag” style widget for displaying your Stack Overflow rep. […]
I have modified your code, pray i do not modify it further. 😀
I had some issues with floats below the widget so i added a clear div tag, i also had issues with my name, since it has funky characters, so i added an htmlentities to decode it.
Here’s the code if you want to update it.
http://cznp.com/sowpw.phps
Thanks 😀
Excellent, thanks, I’ll update the code on here and on WordPress when I get a minute. I did wonder how it would handle all the wierd and wonderful WordPress setups, but I didn’t even consider wierd and wonderful names 🙂
The SO team is complaining that I’m hitting my user page too often from the colo box that hosts my blog, and the only reason I can see is the SO widget. Is there any way we can cache the information or somehow hit it less often?
I’ve seen a mail from SO this morning – I’ll pop you both a reply via email.
how to install this in my wordpress site.
Hey,
I found a typo in your code. There was a missing greater-than in the HTML which was breaking my design. I just modified line 95 in /wp-content/plugins/stack-overflow-gamertag-widget/sowidget.php and it looks like it’s working properly now.
Cheers,
Aiham