Tag Archives: api

Fixing a Mailgun API unknown domain error

I’m using the Mailgun API for a couple of clients, making sure we don’t keep sending email to someone who has marked their previous message as spam.

It should be quite simple to use as the docs are very clear, but I kept getting an ‘unknown domain’ error in the returned message when I used the API with one of my client’s domains rather than the sandbox domain the Mailgun provides.

The fix was to use the EU address for the API: api.eu.mailgun.net rather than the standard api.mailgun.net. As my clients are in the UK, they are put into the EU servers, rather than the American ones.

I didn’t find a simple suggestion to do that, so I’m writing this so I find it next time this trips me up.

5K App: Article Suggester

For my third and final 5K app for the £5 App competition I built a cut-down version of something I’ve been meaning to build for ages, which is part of the reason for having the 5K limit in the first place – it forces you to concentrate on the main point of a script or programme and leave out everything else.

At heart, the Article Suggester is a very simple application: you give it a bunch of text (for instance an article or blog post that you’re writing) and it will suggest a list of articles from the Guardian website.

Behind the scenes, things are slightly more complicated. When the form containing the text is submitted it’s first run through the Yahoo Term Extraction tool, which gives back a list of words and phrases it thinks are important from the text. The script then runs this list through the Guardian’s Open Platform content API and gets back a couple of articles related to each phrase, offering them up as links next to the submitted text to help with further research.

Try out the Article Suggester.

Both the Yahoo API and Guardian API have limits on their use, so if this gets popular it may not work. I’ll post up the source code soon so people can get their own API keys and extend it any way they want.

The code is written in PHP and uses SimpleXML to work through the data coming back from the APIs. Currently it’s only 2,292 bytes, so there’s loads of space left in the 5K, I just don’t have any time to add new bits before the competition presentation and judging on Monday.

If you’re interested in seeing the competition presentations, it’s happening at the Skiff from 8pm on Monday 20th April.

5K App: Portal Me

I enjoyed building my first 5K App, the Twitter Biorhythm bot, so much I started building another app. In fact, I started building the second app. before I’d even finished the bot because it was so easy to put together.

This app. was inspired by Jeremy Keith’s talk at the £5 App meet in February about HuffDuffer, his podcast creation service. Within HuffDuffer Jeremy uses Google’s ‘Social Graph‘ API to help broaden the usefulness of the site without bothering the person using it. For instance, if you give it your Twitter name it will use your Twitter icon as your icon on Huffduffer, and it will also offer links to other popular services that it’s found you on using the Social Graph. You can see this at work on the ‘Elsewhere’ section of a profile, the links are created by looking up where else you have profiles via the Social Graph API.

In the past I have thought it would be useful to be able to put someone’s name in to a web page, and get back a set of their posted information from various sites. This is a bit cyber-stalking like, but it’s helpful to be able to get a quick picture of someone’s online life, especially if you’ve just met them as a potential client or through networking.

The Social Graph information would give me a simple way of looking up at least some information about someone. After a poke around in the documentation I found I could easily build a URL that included the URL of a page about someone that could be included in the graph, e.g. their blog or Twitter page. Giving this to the API and asking for ‘otherme’ information meant it would give me back a bunch of XML which includes profile pages on sites registered to that person, including the URL of RSS/Atom feeds from  those pages. I could take those feed URLs and make a page of posts from the person from various sites.

As this was to be a 5K App, I started knocking the code up in ColdFusion, which only needs a very small amount of code for parsing RSS and Atom feeds using the CFFEED function, and it’s XML parsing is pretty short too.

I got a prototype working and it only needed a couple of K’s worth of code. As I had so much spare, I decided to add some basic caching so it wouldn’t request the RSS feeds every time the page was refreshed.

The caching first checks a directory where feeds are saved. If it can’t find a feed, or the saved one is over an hour old, it goes on to request the feed and save it in to the cache directory. Then it reads the feed out of the cache.

Finally, a bit of styling, giving away the fact that I’m not a designer, and it was finished. The code is 4041 bytes, and you can try it out for yourself here: Portal Me.

It works best with people who have several sites which are registered in the Social Graph, and it only works for sites which are tied to the person by using the ‘rel=”me”‘ microformat code on the link (places like Flickr and Twitter do this automatically for you.)

Here’s a Portal for Jeremy Keith from his website address, and one for my friend Josh Russell based on his Twitter account.

One problem with Portal Me is that the Social Graph isn’t perfect, and if you haven’t tied your accounts together properly it shows some odd effects. For instance, if you make a portal for me based on my Twitter account you get less results than if you look me up via my main website address. I’ve only recently started making sure all of my various profiles link to the same site, and also that the site links back to tie them all together, so it may be sorted out over time.

I’ll put some coments in the code and put it up for downloading soon.

Try Portal Me for yourself.