/** * Shared code that creates a Buzz object and authenticates using OAuth */ function createBuzz() { try { // Use file based storage for the demno, on production systems you would want to use Apc or MySql based storage $storage = new buzzFileStorage('/tmp/buzzCache'); // Create a local user ID based on a session ID (normally you would use some form of authentication to get to a user id, this is for demo only) session_start(); $localUserId = session_id(); // calling performOAuthLogin will do the oauth dance for you (redirecting to google.com where the user is prompted to grant access) $auth = buzzOAuth::performOAuthLogin($storage, $localUserId); // Create the actual Buzz object with our Storage and Auth classes $buzz = new buzz($storage, $auth); return $buzz; } catch (buzzException $e) { die("<b>Fatal error:</b> " . $e->getMessage()); } }
<?php require_once '../src/buzz.php'; $storage = new buzzFileStorage('/tmp/buzzCache'); session_start(); $localUserId = session_id(); $auth = buzzOAuth::performOAuthLogin($storage, $localUserId); $buzz = new buzz($storage, $auth); // Render the @consumption stream $stream = $buzz->getPosts('@consumption', '@me', 30, 20, 20); foreach ($stream->posts as $post) { $titleLink = $post->links->alternate[0]->href; switch ($post->object->type) { case 'note': $content = $post->object->content; } foreach ($post->object->attachments as $attachment) { switch ($attachment->type) { case 'photo': $content .= "create custom html for a photo here"; break; case 'photo-album': $content .= "create custom html for a photo album here"; break; case 'video': $content .= "create custom html for a video here"; break; case 'article': $content .= "create custom html for an article here"; break; }