The Magnify API is patterned after established web APIs and returns highly standardized data. Following practices developed for these APIs will generally work well with Maginfy.
Our Demo Site shows an example use case, demonstrating several layouts and tricks that are made possible by the API. This particular demo is powered by our PHP Library, but you can use your language and platform of choice for equivalent functionality.
If you'd like to use your own PHP class instead of ours, MagpieRSS can be used instead of the builtin SimpleXMLElement parser of PHP5 for convenience and speed. In Python, Universal Feed Parser is a robust Atom/RSS parser that should be able to process feeds returned from the API into data structures you can use. For Ruby, you may want to try RubyRSS. Perl offers a variety of CPAN modules that can ingest Atom. You can even use a Javascript Atom parser and totally AJAXify your application! Or, simply use our PHP library below.
We've built a minimalistic PHP client library to simply the integration of your established PHP-powered site with our functionality. The usage and calling patterns largely mirror the layout of the API, making the PHP class easy to use.
The fastest way to get started is to head over to our Demo Site, containing many usage examples -- all including the source code for the API calls right on the page. You can also grab a source code snapshot for the entire site for a complete picture.
The Magnify API library requires PHP version 5.2.6 or later compiled with SimpleXMLElement and SPL. You can check the version and available components by using phpinfo(); both SimpleXMLElement and SPL are compiled in by default and should be present unless '--disable-simplexml' or '--without-spl' flags are set.
All API calls are dispatched by the main API object MagnifyAPI. You should begin working with the API by instantiating it:
// Instnatiate our object $api = new MagnifyAPI();
The MagnifyAPI object offers methods that correspond to all API resources. You can make any call to group/resource?parameters=... as:
$api = new MagnifyAPI();
$result = $api->group->resource('parameter', 'parameter2');
Parameters are passed in order and aren't named; see the function reference at the end of this document for the parameter formats. For example, to get all videos for user "1234567890ABCD" sorted by title in pages of 12, we can:
$api = new MagnifyAPI(); $user_id = '1234567890ABCD'; $page = 1; $per_page = 12; $sort = 'title'; $result = $api->content->user($user_id, $page, $per_page, $sort);
API calls return Feed objects containing Entry objects for multiple results (most functions) or bare Entry objects (for show($id) functions). You can examine any object with
var_dump($feed);to determine what members are available.
The Entry object exposes all information retrieved from Magnify as public variables for simplicity. You can access them as:
$entry->title;Entry is subclassed for the various types of items that can be retrieved from the API, for example Content_Entry or User_Entry. They share a lot of common functionality, but are not completely interchangeable (polymorphic). When appropriate, entires contain helper methods like
$content->drawIframe( param( 'width' => 400 ) );These helper methods take named arguments that control their behavior but can be omitted. All methods return their value so you can print(), save, etc. Feed is a container object for entries. It implements the Iterator interface, so you can loop over a feed simply using
foreach($feed as $entry){
print $entry->title;
...
}
but you can also access properties like
$feed->totalResults;The Activity_Feed object is a special type of Feed that holds activity entries. These entries can be of three types (comment, review and tagged), labeled accordingly in
$entry->activity. In order to make handling these easier, a helper method is provided for each type that returns a feed containing only the appropriate entries:
$comments = $activity->getComments();NOTE: the feeds produced this way are not copies, and refer to the original feed's entries. If the original (
$activity above) feed is destroyed, the helper feeds will stop functioning.