Posts Tagged ‘API’

Using Mixpanel API In Google App Engine Applications (Python)

Monday, December 14th, 2009

We started using MixPanel to get realtime statistics on user engagement in our application. We’ve been using MixPanel before for funnel tracking, but you can’t really appreciate their service until you start using their event tracking. It is truly realtime (as advertised) – the second the user performs an action on your application, you see it on your dashboard.

Besides the realtime reporting what I really like about MixPanel is the fact that they allow easily reporting from your backend and not only from frontend/Javascript (as opposed to Google Analytics).

Within their documentation they have code samples in many languages, including Python. But their Python sample requires ability to start new processes on the server you’re running – something not possible on App Engine. Therefore I changed it to use URLFetch in RPC mode (so that calls to Mixpanel won’t block the call):

It could be re-factored more, like allowing setting the project token outside the function call, but that I will leave for you to do :) (and if you do, please share with us)

Arik

PHP Wrapper for the Mr. Tweet API

Tuesday, June 2nd, 2009

The Mr. Tweet people announced their new API to the public and I’ve just published on GitHub my PHP Wrapper for the Mr. Tweet API.

PHP Wrapper for Mr.Tweet’s V1 API
API Doc: http://api.mrtweet.com/v1/docs

It uses libcurl and requires PHP 5 >= 5.2.0 for json_decode.
Of course, you can rewrite to use other json decode funtions (or SimpleXMLElement for the XML response) and something
different than libcurl.

While it very straightforward, see MrTweetApiTest.php for example of usage.

Used originally for Topify (http://topify.com/).

Their API is in alpha right now, so you need to request an API key by emailing api@mrtweet.com.

Would love to hear comments and to see people forking it! :)

Arik

Shortening URLs using bit.ly API and PHP+Zend Framework

Friday, April 24th, 2009

Recently for Topify I needed to shorten some long urls (our invite links) and my obvious choice of shortener was bit.ly. I tried looking for PHP wrapper for their API, but only found this project which was way more than I needed. So I’ve decided to write my own simple client using the Zend Framework HTTP Client. Here’s the result:

<?php
function bitly_shorten ($url) {
    $client = new Zend_Http_Client('http://api.bit.ly/shorten');
    $client->setParameterGet(array(
        'version' => '2.0.1',
        'longUrl' => $url,
        'login' => 'arikfr',
        'apiKey' => 'R_03feadf27c1c7c1a1ac3c3e7d6d41a27'
    ));    

    $response = $client->request();
    if ($response->isSuccessful() ) {
        $phpNative = Zend_Json::decode($response->getBody());
        if ($phpNative['errorCode']==0) {
            return $phpNative['results'][$url]['shortUrl'];
        }
    }
    return "";
}
?>

As I said – it’s simple. There’s a lot more to do with it, but it serves the purpose I needed it for and I think it might be useful for others who only want to shorten some urls. If you need more than that, you might want to take a look at the above mentioned project.

Arik

Gravatars to Google Contacts Importer

Sunday, October 12th, 2008

I really like avatars and therefore I’m a big fan of Gravatar. When Google first released their Contacts API, the first thing I though of was creating a small application to sync my friend’s Gravatars to my Google Contacts addressbook. The problem was that the first version of the API didn’t have an option to manage the photos of the contacts. Few months later, Google updated the API to include the option to update the contact’s photos. I played a bit with the new API, but never had the time to write the appliaction.

Yesterday  (October 11 2008), the guys from Automattic/Gravatar wrote a post the summarizes their last year. This reminded me of this small project that I always wanted to code. I’ve decidced to code a first release of the application and put the code on Google Code for other to contribute.

Gravatars to Google Contacts Importer 

I’v decided to make it a .NET application and not a Python script, to address more people (I guess that more people are comfortable with running application than Python scripts). The reason that this isn’t a webapp, is because it takes a whole lot of time to process each contact list. If there was an option to question the Gravatar API for existence of a Gravatar for each email, it would make everything a bit quicker.

It’s .NET 2.0, so I guess there shouldn’t be a problem to run it on Linux using Mono, although I didn’t try that. The code is very simple, so if someone wants to translate it to other languages it’s possible and shouldn’t take too much time.

This is an alpha version, therefore don’t be scared if a nasty exception jumps at you :-) There are a lot of things to imporve, like adding threads to speed up things, time left counter and more. When I will have some more free time, I might add all this.

This is my first opensource project and your comments are mostly appreciated. 

Arik

How To Send SMS Message From Python Via Skype

Friday, October 3rd, 2008

In case you didn’t know, Skype offers an extensive API for their application. This API can be used via Java library, COM module or a Python library. The Java library, COM Module and Python library all share similar features and I decided to try out the Python library. What I wanted to do is to write a simple Python script that uses the Skype API to send SMS message from Skype. After going through their API documention, I was ready to go and the outcome was this short script: 

I think that the code is pretty straightforward and doesn’t require additional explaining. Feel free to ask questions at the comments.
Arik