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
Tag Archives: api
Using JIRA’s REST API to Create a Dashboard
- 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
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
API Serving JSONP
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
Continue reading
PHP Returning Numeric Values in JSON
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.
A Prototype API for Joind.In
Things you need to know:
- The service is an HTTP Web Service. Meaning it’s RESTful apart from when it isn’t
- The endpoint is here: http://api.joind.in
- You can fetch data about events and talks (read-only) at this point
- Formats available are HTML or JSON. The service will guess from your accept header but you can override it with
?format=json
or?format=html
- If you need more columns than you get by default, you can add
?verbose=yes
to your request - Pagination is available, with parameters
resultsperpage
(default 20, set to zero for no limits) andstart
(default zero) - The service supports OAuth1.0a, which isn’t useful at this point as we’re read-only but it will come into play as we add functionality
Examples
Events list: http://api.joind.in/v2/events
Information about DPC11: http://api.joind.in/v2/events/603
Talks at DPC11: http://api.joind.in/v2/events/603/talks
Your Thoughts
Comments are welcome on this post. Bugs and feature requests should go to http://joindin.jira.com, read more about Joind.in and its community at http://joind.in/about
PHPComCon Web Services Tutorial
Invalid Protected Resource URL in Pecl_Oauth
Fatal error: Uncaught exception 'OAuthException' with message 'Invalid protected resource url, unable to generate signature base string'
There are two things to notice about this. The first one is that I should be catching exceptions thrown by this code :) The second is that I could see nothing wrong with my url, http://api.local
. It turned out, after some experimentation, that what is missing here is a trailing slash, and if I supply http://api.local/
, everything works perfectly nicely! I’m unclear if this is intended functionality or not, but if you see this error message and you’re requesting a URL with no path info, make sure you have a trailing slash.