Posts Tagged ‘PHP’

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

How To Create a Teapot with PHP

Wednesday, May 13th, 2009

Saw on @toolmantim’s blog that he turned his blog into a tea pot. He even made a Rack middleware that can turn any Rake app into a teapot. “Cool! it can be cool addition to Topify, too”, I thought to myself. The problem? Topify is PHP and not Ruby. The solution? 6 lines of PHP code:

And now you can do :

arikfr:~ arik$ curl -i -X BREW http://topify.com/
HTTP/1.1 418 I’m a teapot
Date: Wed, 13 May 2009 08:51:07 GMT
Server: Apache/2.0.59 (Unix) PHP/5.2.6 DAV/2
X-Powered-By: PHP/5.2.6
Content-Length: 29
Content-Type: text/html

We do serve ICE Tea, though.

It’s not as elegant as Ruby code or Ruby gem, but it does the work.

If you use this on your own server, please ping me. I would love to hear :)

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

EXCLUSIVE: The Code Change That Was Needed To Increase Facebook Friends Limit

Friday, May 9th, 2008

Today Michael Arrington announced that Facebook lifted their 5000 friends limit. As a tech blogger, I bring you the “behind the scenes” view: the code change that was needed to be done to increase this limit:

fb_friends_limit

For the non techies:

  • line 3: commented out – the previous friends limit defined
  • line 4 – the new friends limit

Shocking. :-)

Arik

Handling RSS Feeds with PHP using Zend_Feed

Monday, February 25th, 2008

Zend Framework is becoming a very comprehensive set of widely needed components for PHP development. As other frameworks offer similar components, one of Zend’s Framework greatest strengthens is the fact that you can use its components as stand alone components and not only as part of the MVC structure. In this post I will show how you can easily use it’s Zend_Feed component to merge feeds.

Recently I though of making one combines RSS feed of both of my blogs and my twitter updates. There are some RSS merging services out there, and there’s also Yahoo pipes which seems that it’s most useful ability is to do various RSS tweaking tasks. As part of my playing around with the Zend Framework, I’ve decided to make this merged RSS feed using the Zend_Feed component. Actually at the end I’ve realized that this merged feed idea is quite useless, but at least this post came out of it :-)

Most of the basic actions, like importing an RSS feed, creating an RSS feed and more are covered in the Zend Framework manual. In this post I will elaborate more on the more advanced topics, like sorting and merging RSS feeds but I will also go briefly over the more basic stuff as well.

So let’s begin.

(more…)