Developers > Code library for PHP
This library is released under the BSD license.
Requirements: PHP 5.0, curl extension. If you need OAuth authentication, then you also need to install PECL/OAuth.
Installation: simply copy the *.inc files to your PHP source code directory. Include just this file:
require_once('likeorhate.inc');
There are many files in the test/ subdirectory, which can be used
as a tutorial. They are very simple and well documented. We'll run through
test/thing.php as an example.
<?php /* * likeorhate.com * Copyright (c) 2008-2010 likeorhate.com * * Released under BSD license. */ /* * This file shows how to get data about things. */ /* * Generates a random key. Used to get a non-existing thing. */ function randomKey($length = 32) { $pattern = "1234567890abcdefghijklmnopqrstuvwxyz"; $key = ""; for($i = 0; $i < $length; $i++) { } return $key; } // Base file. Include only this file, the others are included automatically. require_once('../likeorhate/likeorhate.inc'); // Get the base singleton, which is used to setup the requests. $loh = LikeOrHate::singleton(); // Use the sandbox server. We can mess it as much as we want, so it's great for // debugging. Use "production" when your application is deployed. $loh->setServer('sandbox'); // construct the thing. Here we are using a string (its label), so we set id=0. $likeorhate = new LoHThing(0, 'likeorhate'); // get basic information $base = $likeorhate->getBase(); if ($base['status']) { echo 'Base: '; } else { echo "Error getting base.\n"; } // get extended information $information = $likeorhate->getInformation(); if ($information['status']) { echo 'information: '; } else { echo "Error getting information.\n"; } // get up to 5 comments, starting at 0, $comments = $likeorhate->getComments(0, 5); if ($comments['status']) { echo 'comments: '; } else { echo "Error getting comments.\n"; } // get trackback information $trackback = $likeorhate->getTrackback(0, 5); if ($trackback['status']) { echo 'trackback: '; } else { echo "Error getting trackback.\n"; } $notexist = new LoHThing(randomKey(32)); // this should not exist $base2 = $notexist->getBase(); // we expect $base2['data'] == null (does not exist) ?>
Here's a small tutorial on how to use 3-legged OAuth. This is what you need if you want to access LikeOrHate on behalf of other users securely. In this example we will create a new thing on behalf of another user. Let's start by noting that we have three entities here:
Rest of tutorial to come.