Welcome 54.205.15.219 to 4D4M D07 N37  b a f t l e

< -
0102030405060708091011
+ >

The Site Face Lift Continues
08.03.13
18:02:48


Today I focused mainly on getting the site's look finished up. I'm pretty happy with the layout and the overall stylization of the site. The biggest addition today was finishing up the some things with the 'blog list' site which is now the default page of the site. This site will list the latest five, or whatever I decide later, blog post. It list them out newest to oldest and displays the first 512 characters of the post. Then cuts it off and offers you a 'More' link that takes you into the old style blog view page. As I mentioned before I wanted to add titles to the blog post and I have that done as well and you can also view the full blog post by clicking on said title. Finally I created a side bar on the blog list view that currently only houses my custom Twitter feed. The feed right now only does plain text and only shows my last five tweets but I'm going to attempt to do some text manipulation to generate automatic links for both the users (@username) and the links (http:/t.co/variable) in the tweets.

Now, for a little ranting. So a previous version of my site had a default landing page that gave you some information on the site like latest article (when I did articles), latest blog, latest tweet, and other things. I use to have a piece of code that was simple and elegant to grab the latest tweet. I figured I'd just use that and modify it to grab the last five tweets for this new side bar. I quickly found out that code no longer works. Apparently they've depreciated most of that old API so I went to look up how to do it again. I fell into a nightmare of the new 1.1 API and its OAuth bullshit. I kind of get the point but it really is a lot of effort to create / register an app with Twitter. Then I have to get all my API keys and secrets. Then I have to right some sort of authentication piece which is amazingly complicated, although there are a couple decent pre-made ones out there.

Needless to say I'm far too lazy for that, especially on my simple little site here. So I actually found a way to do an unauthenticated query and the only real difference is I can only query the API 150 times and hour verses 350 you get if you go through the pain of authenticating. So for now I'm doing that because it cut my work load down a ton. So I thought I'd take this opportunity to try and show off some of the code I've done. I'm sure there's a million ways better to do this but this is what I've done for the unauthorized Twitter feed.

$user = "4d4mdotnet";<br /> $count = 5;<br /> $apiurl = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=".$user."&count=".$count;<br /> <br /> $ch = curl_init();<br /> curl_setopt($ch, CURLOPT_URL, $apiurl); <br /> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); <br /> $output = curl_exec($ch); <br /> curl_close($ch); <br /> <br /> echo "<div class='tweet'>Twitter Feed</div>";<br /> $tweet = json_decode($output);<br /> <br /> if (isset($tweet->error)) {<br /> echo "Rate Limited by Twitter.";<br /> echo "<hr class='listhr'></hr>";<br /> } elseif (isset($tweet[0]->text)) {<br /> for ($i=1; $i <= $count; $i++) {<br /> $display = $tweet[($i-1)]->text;<br /> echo "<div class='tweet'>".$display."</div>"; <br /> echo "<hr class='listhr'></hr>";<br /> }<br /> } else {<br /> echo "Something else went wrong.";<br /> echo "<hr class='listhr'></hr>";<br /> }

I had to dress it up a little so it did some basic error checking. That way when I get super popular and the rate limit kicks in there will be a pretty error message instead of a server error the blows the page up. Hopefully I'll take some time to figure out the authenticated version since that's the way Twitter is pushing people and I'm sure they'll eventually depreciate this version.


π rss Copyright © 2005 - 2017 4d4m.net