Flash

Create a Twitter OAuth Application With Tweetr Using Single Access Token

What do you do when you want to use the Twitter API with your own account, and don’t need or want users to login via the PIN OAuth dance? You can use a single access token/secret in place of the authenticated token/secret and get all the access you need.

Note: the authenticated user in this scenario is you, the owner of the application.

For this example I’m using Tweetr, an AS3 library for accessing Twitter from your Flash or Flex application. Tweetr requires as3crypto. Details and downloads here: http://wiki.swfjunkie.com/tweetr:downloads

Make sure you grab the proxy php and load that up on your server so you can have a service host. Run the install.php so it’s ready to go. This is a nice script providing caching so you get a little speed boost and don’t run over your Twitter API limit.

Ok, let’s get to it.

Create a Twitter Application, and make note of the Consumer key and secret on the settings page. Then on the right side of the profile click the button labeled “My Access Token”. Grab that Access Token and Access Token Secret. This is referred to as a “single access token”, “one access token”, or “single user access token”. Docs: http://dev.twitter.com/pages/oauth_single_token

In your Flash application, implement Tweetr with OAuth. Import and other implementation details are omitted below.

[actionscript]
var serviceHost : String = “http://your_twittr_proxy_php_setup”;

var tweetr:Tweetr = new Tweetr();
tweetr.serviceHost = serviceHost;       

oauth = new OAuth();
oauth.serviceHost = serviceHost;
         
oauth.consumerKey = “CONSUMER_KEY”;
oauth.consumerSecret = “CONSUMER_SECRET”;
oauth.oauthToken = “MY_ACCESS_TOKEN”;
oauth.oauthTokenSecret = “MY_ACCESS_TOKEN_SECRET”;
tweetr.oAuth = oauth; 
[/actionscript]


And then you need to…wait, sorry, that’s all there is. Start making calls to the API and listening for results.

[actionscript]
tweetr.addEventListener(TweetEvent.COMPLETE, handleLoad);
tweetr.addEventListener(TweetEvent.FAILED, handleFail);
tweetr.getUserTimeLine(null, null, null, 0, 0);
[/actionscript]

[actionscript]
var tweets:Array = [];
private function handleLoad(event:TweetEvent):void
{
for(var i:int = 0; i

< event.responseArray.length; i++)
{
var statusData:StatusData = event.responseArray

;
        tweets.push(statusData);
      }
  // ... do something magical with the tweets
}

private function handleFail(event:TweetEvent):void
{
trace("Failed to get data");
// ... handle the disappointing failure…maybe a whale…just a thought
}
[/actionscript]

There are plenty of good tutorials out for using Tweetr, though beware of any too old. Twitter phased out basic authentication August 2010.

A couple I checked out:
Mark Doherty: Tweetr App Video Walkthrough
swfjunkie: PINless OAuth with Tweetr

I also want to note that it’s difficult to secure anything in a Flash application, and the key, token, and secrets are no exception. In this example they are right there in the code, unencrypted. SWFs are easily decompiled. If you dream up a solid security solution that doesn’t require a mountain of effort, please let me know.


Categories: FlashFlexAIRPermalink

Slides and Demos from Flash Camp St. Louis 2010

What a great day! I loved seeing the awesome turnout of Flash designers and developers from around the area, including many interactive compatriots I hadn’t seen in quite a while. You guys are awesome!

Here are my slides and an archive of the demos I showed during my session.

The demos are FDT projects, so head over to Powerflasher and get your demo copy of FDT4. And if you don’t have a license, be sure to follow @brunofonzi, @brittrking, myself, and many others that seem to weekly be tweeting or retweeting ways to get a free Pure license.

To use the demos, open a new workspace in FDT, choose to Import > General > Existing Projects into Workspace. Browse to the extracted the ZIP file and choose each project individually. It should end up looking like this:

image

In the demos you’ll find 3 projects:

1) AssetsExamples

This is the demo I also performed step by step in the screencast on Vimeo. I demonstrate how to create assets in Flash Pro, produce a SWC file, make that SWC available in an FDT (or Flash Builder) project and then a variety of ways you can use and add behavior to those assets.

2) LoaderMaxExample

This code demonstrates the flexibility of bulk loading a variety of different asset types by defining them in an XML manifest document with custom properties telling LoaderMax how to handle them.

NOTE: for this example and the next you will need to set your Flash Player security to so you don’t get a SandBox violation. Open the FDTLaunch.cfg file you’ll find here: ~/Library/Preferences/Macromedia/Flash Player/#Security/FlashPlayerTrust/ and add paths to your project locations. Then restart FDT. Here are mine:

file:////Users/dave/work/SimplyProfound/LoaderMaxExample/bin/
file:////Users/dave/work/SimplyProfound/SWFLoaderExample/bin/

During my talk I also showed code from the STLTweets LouFest twitter display that I did with the guys at Infuz. I can’t share the entire app, but the relevant code below demonstrates how you can load images directly into containers, define the desired size, and then the scaling parameters to make sure your image fits and fills that space when it’s loaded. Awesome mojo from Greensock!

photoLoader = new ImageLoader(vo.linkThumbnail, {smoothing:true, container:tweet.imgPhoto, width:400, height:300, scaleMode:"proportionalInside"});
photoLoader.load();

iconLoader = new ImageLoader(vo.profileImageURL, {smoothing:true, container:tweet.imgUserIcon, width:60, height:60, scaleMode:"proportionalOutside"});
iconLoader.load();

3) SWFLoaderExample

This set of examples demonstrates using a utilities like CASA Lib to load linked assets from swf files. This method is more akin to the old school AS2 way of doing things and lacks the strong typing I prefer (and why I use SWCs more often). It’s a very cool and useful way of loading multiple swfs and accessing the libraries.

Download Demo Code Projects


Categories: FlashGeneralFlexPermalink

My Interview with FDT for Flash Camp St. Louis

The crew over at FDT asked me for an interview, and I’m excited I was able to oblige. They are a sponsor for our upcoming Flash Camp in St. Louis where I’ll be speaking during the last session of the day.

During my session I’ll be giving away a free FDT Pure license. That’s a $129 value, and all you have to do is listen to me tell some stories, play with some code…so get yourself registered and I’ll see you there!

To read the full interview, head on over to the FDT blog: http://fdt.powerflasher.com/blog/?p=2662


Categories: FlashGeneralPermalink