Bit.ly API: Bundles and Short URLs

I am a huge fan of bit.ly and use their tools for a wide variety of different things. They recently did a big relaunch with some lovely new features, which are for the most part pretty good, but which are inaccessible in places. In particular, it seems that there aren’t any short URLs for the bundles – which is annoying for me as I use that feature a lot!

To get around this, I used their API to make a page which lists my bit.ly bundles, and creates shortlinks for each of them (once you’ve created a shortlink for a given URL once, bit.ly just re-uses the same ones the next time you ask to shorten the same URL, so this is less silly than it sounds).

In case the code is helpful, I thought I’d share. Continue reading

Fetching Your Talks from the Joind.In API

I’m a regular speaker at a variety of (okay, mostly technical, so not really that varied!) events, and I submit talks to many CfPs (calls for papers). Whenever this happens, I tend to look back at whether I have any existing talks that I gave and liked and which would be a good fit. I use my joind.in speaker page for this: http://joind.in/user/view/110 as it’s simpler than dredging through my directory of talks/articles on my hard drive (this is now rather large and unmanageable!).

I’ve recently been thinking that I should also do a better job of linking through to the various talks I’m giving/have given – and at around the same time I was contacted by the good folk at mojoLive about integrating against joind.in. To cut a long story short, the joind.in API now has the functionality for users to retrieve their list of talks! Continue reading

Using OAuth2 for Google APIs with PHP

I’ve been working on something recently where I’m pulling information from lots of places onto a dashboard. Each API has its own little quirks so I’m trying to write up the ones that weren’t idiot-proof, mostly so I can refer back to them later when I need to maintain my system!

I’ve written about Google and OAuth before, but that was OAuth v1.0, and they are introducing OAuth2 for their newer APIs; in this example I was identifying myself in order to use the Google Plus API (which turns out not to do anything you’d expect it to do, but that’s a whole separate blog post!). Continue reading

Using JIRA’s REST API to Create a Dashboard

If you read this blog often, you’ll know that I am:

  • crazy about APIs
  • living with some accessibility issues

Put these two things together and what do you get? Actually don’t answer that! Today what you get is an example of integrating with JIRA’s REST API, because their recent “upgrade” locked me out of the issue listings pages completely and I really do need to be able to see a list of bugs! Their bug editing screen is quite usable, so it’s just the list that I need here, but you could easily call their other API methods as you need to. Continue reading

Google OAuth 403 Response

I had an issue this week on a system which has been working fine for a while, but stopped fetching some data from google’s user account API. I was getting a 403 response from the API, which seemed odd. Luckily I was logging OAuth::getLastResponse() to my error logs (this is PHP code, and you need to call OAuth::enableDebug() before you make the request to get this output) so I could see that I was getting the following back from Google:



  
    GData
    sslRequired
    SSL is required to perform this operation.
  

Closer inspection shows that for one of the google endpoints, I had a prefix of http:// rather than https://. Those single-character bug fixes that take hours to find are my favourite!

Building a RESTful PHP Server: Output Handlers

This is the third installment in my series about writing a RESTful web service in PHP (the previous entries are about understanding the request and routing it. It is probably the last one but there are a few other things I’d like to cover such as error handling, so I might keep adding to it, especially if I get any particular requests or interesting questions in the comments. So far we’ve covered parsing requests to determine exactly what the user is asking for, and also looked at routing to a controller to obtain the data or perform the action required. This post gives examples of how to return the data to the client in a good way. Continue reading

API Serving JSONP

disclaimer: I am not a client-side developer, and I don’t write javascript. However I am committed to supplying useful APIs of all kinds, and JSONP falls into this category

Early in the development of the new Joind.In API, someone else started consuming the service to populate the javascript widgets they were making*. Since these scripts are intended to be used on many external pages, and they retrieve data from the joind.in API, cross-domain issues were a problem. Continue reading

QR Codes with Google Charts API

I’m a big fan of the google charts API – it draws much better-looking graphs than I would ever manage and all I have to do is assemble the right URL to make it work. I recently got a feature request to add QR codes to joind.in, so that speakers and event admins could easily allow people to link in to a particular talk page.
Continue reading

PHP Returning Numeric Values in JSON

When I wrote about launching a prototype of a new joind.in API, quite a few people started to try it out. My friend David Soria Parra emailed me to point out that many of the numbers in the API were being returned as strings. He said:

It’s just a standard problem of PHP REST services. When I try to access it with java I have to convert it over and over again to ints.

I did have a quick look at the PHP manual page for json_encode but I didn’t see anything mentioning this. A few weeks later (my inbox is a black hole and it takes a while to process these things) I fell over a throwaway comment to an undocumented constant JSON_NUMERIC_CHECK, and I added the constant name to my todo list. In the time it took for me to actually get around to googling for this, some wonderful person updated the PHP manual page (this is why I love PHP) to include it as a documented option, and someone else had added a user contributed note about using it.

It turns out, this constant does exactly what I need. Here’s a simple use case:

echo json_encode(array('event_id' => '603'));
echo json_encode(array('event_id' => '603'), JSON_NUMERIC_CHECK);

and the output:

{"event_id":"603"}
{"event_id":603}

There are probably some situations in which you don’t want all your looks-like-a-number data to be returned as a number, but for now it seems to be a good fit for api.joind.in.