Tuesday, September 23rd, 2008

Yammer API Client Library

Update: Yammer recently modified their API to only allow OAuth style authentication. As a result, this library has become defunct. If you update this library to support OAuth, please let us know.

Yammer is a new microblogging service that has been described as “an enterprise version of Twitter”. Instead of asking, “What are you doing?” Yammer asks, “What are you working on?”

Yammer has released their API with some great documentation, so we’ve written a library for building our own tools (RSS feeds, status updates on intranet pages, etc…)

Anyone can start a Yammer account for an organization (defined by email domain), and many services, including IM, SMS, and email integration are free. Optionally, organizations may claim their domain for a fee, allowing for more advanced control and customizations.

Enjoy!


What is this?

The Arc90_Service_Yammer class makes HTTP requests to the Yammer API using PHP and cURL.

How Do I Use It?

To use Arc90_Service_Yammer in your PHP project, just follow these simple steps:

Download The Code

Click on the icon below to download the source code:


Download

The file, Arc90_Service_Yammer.zip, contains the source, usage instructions and phpDoc
generated documentation.

Add the code to your PHP project

You’ll need to add the contents of the ‘lib’ folder (the ‘Arc90′ folder and its contents) to
your include path.

Create an Arc90_Service_Yammer API client with a valid Yammer username (email address) and password

<?php
require_once('Arc90/Service/Yammer.php');
$yammer = new Arc90_Service_Yammer('username', 'password');

Arc90_Service_Yammer returns an Arc90_Service_Yammer_Response object containing the
requested data and all of the HTTP metadata recorded by cURL

Data may be requested in any format supported by Yammer (currently XML and JSON). The default type is JSON.

<?php
require_once('Arc90/Service/Yammer.php');
$yammer = new Arc90_Service_Yammer('username', 'password');
// Gets the 20 most recent messages posted to your domain in JSON format
$response = $yammer->getMessagesAll();
// Print out the data
echo $response->getDataString();
// Casting is also supported. This does the same thing as above.
echo (string) $response;
// Data is also wrapped as an object
foreach($response->messages as $message)
{
print_r($m);
}
// If Yammer returned an error (401, 400, etc), print status code
if($response->isError())
{
echo "Error status: " . $response->http_code;
}
}

Documentation

Review the complete documentation for a full
list of all functions available with Arc90_Service_Yammer.

Licensing

This arc90 tool is licensed under a BSD license.

Discuss

Feel free to offer feedback over on the blog.

Comments are closed.