Other Websites

  • SeaCloud9 Interactive
  • SeaCloud9 Commercial Development
  • i-os
  • stArcade9

Brendon Smith Social Networks

  • On Linkedin
  • Bookmarks
  • On Twitter
  • On Facebook
Open ↓ Close ↑
  • Home
  • Subscribe
Browse: Home / ActionScript, Flash, Flex, i-create, MashUp / ZendAMF and the Twitter API
i-create | therefore-i am
i-create | therefore i-am | a blog about opensource technology and rich internet applications
 

ZendAMF and the Twitter API

By Brendon Smith on August 3, 2009

 

Have you ever had the urge to roll your own twitter? Well I have and I have tried a number of methods to come to the conclusion I needed to write everything from scratch. So I did and I wouldn’t say that I wasn’t without help. I did study Lee Brimelow’s gotoandlearn.com ZendAMF tutorial. So I went about downloading and install zend on my server and I found it was extremely easy to use. One of the many things that attracted me to the Zend framework were the prebuilt services. The zend framework is a mature framework that has a great deal to offer developers so I will briefly show you a simple amf flash gateway built with zend to fetch the twitter service. Also please note you will have to create your own classes if you want to extend this but it should be pretty easy to do considering..
Click to go to example

So first off download the zendframework. Configure your zendAMF endpoint.
Create your own ZendAMF endpoint:

<?php
error_reporting(E_ALL|E_STRICT);
ini_set("display_errors", "on");
 
ini_set("include_path", ini_get("include_path") . ":/home/toYourZend/FrameWorkHome/frameworks/zendFramework/library/");
require_once('Zend/Amf/Server.php');
require_once('TwitService.php');
 
$server = new Zend_Amf_Server();
//adding our class to Zend AMF Server
$server->setClass("TwitService");
echo ( $server -> handle() );
?>

Now configure your zend Twitter Service
Create Your Twitter Service Class:

<?php
error_reporting(E_ALL|E_STRICT);
ini_set("display_errors", "on");
 
ini_set("include_path", ini_get("include_path") . ":/home/toYourZend/FrameWorkHome/frameworks/zendFramework/library/");
require_once ('Zend/Service/Twitter.php');
require_once('VOgetFriendsTimeline.php');
//connection info
 
class TwitService {
	public $tmp;
	public $twitter;
	public $response;
 
	public function __construct()
	{
	}
 
     public function getfriendsTimeline() {
     $twitter = new Zend_Service_Twitter('YourUserName', 'YourPassword');
	 $response = $twitter->status->friendsTimeline();
	 $tmp = new VOgetFriendsTimeline();
	 for ($i = 0; $i <= 18; $i++){
			// array_push($tmp->userTwit, $response->status[$i]);
	 		array_push($tmp->userTwit, (string)$response->status[$i]->user->screen_name);
	 		array_push($tmp->statusPic, (string)$response->status[$i]->user->profile_image_url);
	 		array_push($tmp->locTwit, (string)$response->status[$i]->user->location);
     		array_push($tmp->friendsTimeline, (string)$response->status[$i]->text);
	 	}
	 return $tmp;
	 }
 
	 public function UserPostUpdate($tweet){
	 $twitter = new Zend_Service_Twitter('YourUserName', 'YourPassword');
	 $response = $twitter->status->update($tweet);	 
	 }
 
 
}

Now configure your flash variable object that is exposed by the service.

<?php
class VOgetFriendsTimeline {
     public $user_twit;
     public $pass_twit;
     public $locTwit = array();
     public $friendsTimeline = array();
     public $statusPic = array();
     public $userTwit = array();
     public $text;
     public function __construct()
    {
    }
}

Finally configure your flex project to consume the service.

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="600" height="300" initialize="init()">
	<mx:Script>
        <![CDATA[
        	import com.SampleTitleWindow;
            import mx.events.MenuEvent;
            import mx.controls.Alert;
            import mx.collections.*;
            import mx.managers.PopUpManager;
            import mx.controls.Alert;
			import nl.demonsters.debugger.MonsterDebugger;
			import flash.net.*;
			public var nc:NetConnection = new NetConnection();
			public var resp:Responder = new Responder(onResult, onError);
			public var resp1:Responder = new Responder(onError);
			public function init()
			{
			nc.objectEncoding = ObjectEncoding.AMF3;
			nc.connect("http://yoursite.com/toYour/zendEndpointAMF/index.php");
			trace("I was ran!");
			nc.call("TwitService.getfriendsTimeline",resp);
			}
 
			public function onResult(e:Object)
			{
				trace("Recieved Object...");
				//userPosts.dataProvider = e.friendsTimeline;
				var arr:Array = [];
				for (var i:int = 0; i < e.friendsTimeline.length; i++ )
				{
                    var obj:Object = {};
                    obj.text =  e.friendsTimeline[i];
                    obj.from =  e.userTwit[i];
					obj.pic = e.statusPic[i];
 
                    arr.push(obj);
				}
				trace(e);
				datagrid.dataProvider = arr;
			}
			public function zendPost()
			{
				var tweetPost:String = new String();
				tweetPost = twitPost.text;
				nc.objectEncoding = ObjectEncoding.AMF3;
				nc.connect("http://yoursite.com/toYour/zendEndpointAMF/index.php");
				trace("I was ran!");
				nc.call("TwitService.UserPostUpdate",resp1,tweetPost);
			}
 
			public function onError(e:Object)
			{
				trace("And the Error is !!!!");
				trace(e);
			}
 
		]]>
    </mx:Script>
	<mx:VBox width="100%" minWidth="600" height="100%">
	<mx:VBox width="100%" minWidth="600" height="80%" verticalAlign="top" horizontalAlign="center">
    <mx:DataGrid id="datagrid" width="100%" minHeight="150" maxHeight="200">
        <mx:columns>
            <mx:DataGridColumn headerText="Tweet" dataField="text" wordWrap="true"  />
			 <mx:DataGridColumn headerText="Avatar" width="150" id="imgAvatar" itemRenderer="mx.controls.Image" dataField="pic" />
            <mx:DataGridColumn headerText="@user" width="150" dataField="from"/>
        </mx:columns>
    </mx:DataGrid>
 
 
	</mx:VBox>
	<mx:VBox width="100%" verticalAlign="top" horizontalAlign="center">
	<mx:HBox width="98%" verticalAlign="middle" height="10%" horizontalAlign="center">
	<mx:TextArea id="twitPost" width="90%" horizontalCenter="true" ></mx:TextArea>
	<mx:Button x="10" y="10" label="Post" click="zendPost()" />
	</mx:HBox>
	</mx:VBox>
	</mx:VBox>
</mx:Canvas>

Code

Thats it! View the live example here!

Other Cool Twitter Mashup links can be found:

Twitter MashUp Links


Don’t forget to check out Lee Brimelow’s GotoandLearn AMF video.

Zend framework
Zend Services

  • Share/Bookmark

Related posts:

  1. Twitter and Google Maps
  2. Away3D with Hype Fish Tank
  3. 404 Errors Hyped With PaperVision3d pt. 2
  4. Tweet Tank in Away3D and Hype pt. 2
  5. Tweet Tank in Away3D and Hype

Posted in ActionScript, Flash, Flex, i-create, MashUp | Tagged ActionScript, amf, Flex, php, socialnetworking, twitter, zendamf, zendframework

Brendon Smith

GUI Development, Action Script, Java Script, .NET, AJAX, Java, PHP, CakePHP, Mashup Development, Flash, Silverlight, C#, XML, SQL, Apache, IIS, Photoshop, Fireworks,etc.. Oh, and Biking and Camping

  • Biju Subhash
    thank you for sharing... :D
blog comments powered by Disqus
« Previous Next »
 
 

3d ActionScript Adobe Air Android Apollo Apple art as3 Away3D C# CakePHP CSS Experiment Flash Flash Develop Flex Games Generative Design Google HTML5 hype JavaScript Joshua Davis JQuery JSON Life Linux MashUp OpenSource Open Source PaperVision3D PC History Processing quick tip RIA Silverlight Technology/Internet travel twitter Web webGL Webware XML Yahoo Pipes

WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.

  • Monthly
  • Yearly
  • Links
  • August 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • agit8
  • Away3D
  • Ben Nadel
  • Bit-101
  • Bruce Jawn
  • Causecast
  • D.I.Y.
  • Dr Woohoo
  • draw.logic
  • Flight404
  • Flong
  • generatorX
  • gSkinner
  • haXe
  • Jonathan Snook
  • Joshua Davis
  • Jot
  • Kirupa
  • LifeHacker
  • Make
  • Minor White
  • Mr Doob
  • NihiLogic
  • NurseOnTheRun
  • octane42
  • OpenFrameWorks
  • Processing
  • PV3D
  • Senocular
  • Sephiroth
  • ShineDraw
  • Stroep
  • SWX
  • Tech News
  • Toxi
  • UnitZeroOne
  • World We Live In
  • ZeusLabs

Photos

myth.jpg

Recent Comments

  • seacloud9 on Tweet Tank in Away3D and Hype pt. 2
  • Brendon Smith on Tweet Tank in Away3D and Hype pt. 2

RSS LifeStream

  • Elysium
  • Giles Bowkett: Archaeopteryx: A Ruby MIDI Generator
  • Grant Nestor » Blog Archive » Generative music, huh?

Copyright © 2010 i-create | therefore-i am.