Aug 21, 2013 by Matt | Posted in Services and Tools
RandomUser is a new API that returns a JSON object with a randomly generated persona—complete with name, avatar and email address—for your testing purposes. The site suggests using it for design mockups, but the fact that it’s an API opens up plenty of possibilities for more programmatic uses. If you need to fill in a couple dozen users to test an application, you could write a script to populate the database with ones pulled from RandomUser.
The API is neat, but a little limited so far. Hopefully it will be expanded in the future with some additional info.
Jul 3, 2013 by Matt | Posted in Coding
What can you do if you don’t like either option?
I’m using this right now on my personal blog, since Twitter’s new widgets don’t look very good when they’re crammed into a narrow sidebar.
Jan 9, 2013 by Matt | Posted in Coding, Featured
Back in 2009, I wrote a post on how to write a simple PHP script to call on the Twitter API and update your status. Despite its popularity, the information hasn’t been relevant in some time. (Things certainly have changed since then!) The Twitter API has changed a lot over the years, and it’s not so simple that you can get a newbie up and running with a few lines of code.
The mandatory usage of OAuth tokens, rather than a simple username and password combination, for API requests has greatly strengthened account security, but it’s one of the prime hurdles complicating the process. More recently, XML support was removed in favor of JSON, URL structures changed to include an API version, and authentication is now required for every request.
Fortunately, you don’t have to deal with the little details. You can use a library that does the heavy lifting for you, rather than reinventing the wheel. Sure, there are resources to learn how to do it the hard way, but I assume that you want a quicker solution if you’re reading this.
Step 1: Download tmhOAuth
Download the tmhOAuth library from GitHub. This package will handle interactions with the Twitter API once you include it from your script. (It requires at least PHP 5.1.2 and the cURL extension.)
Continue reading →
Jun 28, 2012 by Matt | Posted in Services and Tools
Historically, processing monetary transactions online has been a major pain. Conniving financial institutions would force you to pay tons of extra fees, requiring merchant accounts and other junk. Then Stripe came along, bringing some sanity to the e-commerce world.
With Stripe, you get a no-hassle API and minimal fees. 2.9% + 30 cents, payed out to any bank account. The only requirement is that you set up HTTPS for customers’ safety. (Technically, there is one other thing that may be an issue: Stripe is only available to US merchants for the time being.)
Nettuts+ has an excellent tutorial on how to set up a Stripe account and process transactions through the API: So You Want to Accept Credit Cards Online?
The most difficult part is probably purchasing an SSL certificate and setting your server up to use HTTPS. Some hosts sell certificates, and may be able to configure your server for you. If you’re on your own, though, RapidSSL seems to be a good option. (They’re affordable and on the trust list of most browsers.)
So You Want to Accept Credit Cards Online? [Nettuts+]
Jun 18, 2012 by Matt | Posted in Hosting
Here’s a cool thing I bet you didn’t know could be done with the NGINX server: proxying APIs from web services. Why would you want to do that? Well, for starters, you can avoid running into cross-domain scripting issues.
You can read how to do all this in an informative blog post by the founder of DuckDuckGo. It’s pretty much a matter of adding a location block that uses the
proxy_pass function to pass the request along.
nginx JSON hacks [Gabriel Weinberg]
Oct 24, 2011 by Matt | Posted in Coding, Featured
iOS has a simple event-based XML parser built in, which makes it fairly easy to do less involved parsing operations without having to load up a third-party framework. This tutorial will show you how to build a simple iPhone application that will download an XML feed from Twitter containing a user’s tweets, and then display them with a pretty UI. (You could easily adapt this to parse other XML documents, such as RSS feeds.)
Jan 24, 2011 by Matt | Posted in WordPress
WP Engineer had an interesting post recently about a WordPress “Transients API” that is used for caching bits of data temporarily. I often use the Options API to cache things from external servers, such as Twitter statuses, so I don’t hit Twitter’s servers more often than necessary (which would slow down page loads). The Transients API is similar, but with the addition of an expiration field. This makes it a much easier solution, even without its other added benefit.
Also of note is that Transients are inherently sped up by caching plugins, where normal options are not. A memcached plugin, for example, would make WordPress store transient values in fast memory instead of in the database. For this reason, transients should be used to store any data that is expected to expire, or which can expire at any time.
It’s simple enough to use the API. You just call the set_transient(), get_transient() and delete_transient() functions where appropriate. You can read up on the usage over at WP Engineer or the WordPress Codex.
Oct 11, 2010 by Matt | Posted in Coding, Featured
You’ve probably seen a QR code before, even if you didn’t know what it was at the time. It’s a little square matrix barcode that can be read by either a specialized scanner or a cellphone with the right software. UPS puts QR codes on their packages for tracking purposes, and many Android phones come with QR readers preinstalled for easily sharing links to apps.
A QR code can contain any sort of textual information, which will be decoded by a QR reader. A web address, a simple message, a phone number, etc.. A good QR reader should figure out what the decrypted data is and act upon it accordingly. If it’s a web address, it will display the web page. If it’s a phone number, it should display the number and offer to call it.
Users of the iPhone or fourth-generation iPod Touch can use a free app like QR Reader to scan QR codes.
What can you use a QR code for? There are plenty of possible applications. Magazines could print QR codes that let you quickly jump to a web page. (Anyone remember the CueCat?) Advertisements could have QR codes that offer more information. You could put a QR on your business card. Want to move a web page you’re reading from your computer to your phone? Create a quick QR matrix and scan it right off the screen!
Now for the fun part… How do you make your own QR codes?
Continue reading →
Aug 6, 2010 by Matt | Posted in Coding
If you’ve ever played around with the Twitter API, you’ll know that many functions require authentication with either a username/password combination or OAuth. Soon Twitter will be turning off basic authentication for security reasons, in favor of the more complex OAuth protocol. There are plenty of benefits, for Twitter and for users and for developers, but the transition will be a bit of a pain.
Fortunately, Net.Tuts+ has put together a tutorial explaining how to implement OAuth authentication in a Twitter application.
It’s a more complicated than it should be to implement the authentication dance (but it’s very easy for the end user, thankfully). There is one plus to using one of the Twitter OAuth libraries: it’s easier to handle API requests. Need to get a user timeline? If you’re already authenticated, you can just do this:
$nettuts_timeline = $twitteroauth->get('statuses/user_timeline', array('screen_name' => 'nettuts'));
No worrying about cURL or file_get_contents(), the library’s classes take care of all of the boring stuff for you.