I have build a little Twitter AS3 library which handles Twitter OAuth authentication and let’s you update your Twitter status. The lib basically uses the OAuth AS3 lib and should be a good example how to use the actual OAuth lib.
This is still basic functionality but since it’s open source someone may fork and extend it. To get a simple idea of the current feature-set have a look at the ITwitter interface.
Further I have build a simple Flex 4 example AIR app which shows things in action. The only thing you need to do upfront is registering a Twitter app to obtain an OAuth consumer key and secret which you have to add to the example:
BTW: You maybe have already granted access to your Twitter account for some apps which you can check here.

Sonke
Great post!
For a personal project I am building an AS3 only web based Twitter search and client application. According to Twitter’s FAQ, they recommend using Oauth moving forward as a means of authentication. But from what I’ve seen, 3rd party libraries (Tweetr, twitterscript, SWX) don’t yet implement OAuth. Are you aware of any objective comparison between the various Actionscript Twitter libraries available? You mention that Twitterscript ‘The API is not really my taste ‘, could you elaborate on that a bit? As a newcomer to the Twitter API just trying to get a handle on which approach makes sense for my needs…Thanks!
Twitterscript does not use OAuth and I didn’t like the API design though. However, this is of course personal taste.
Regarding search I don’t have anything to recommend, sorry.
Hi Sönke
Apparently I am missing “airspark.swc”, as I get the error message ‘Unable to locate specified base class ‘spark.components.WindowedApplication”
I downloaded and am using the latest nightly build of the sdk but still no luck…can you help?
Are you building a web app or air (desktop)?
If you are using Flash Builder you should enabled “Include AIR libraries”.
got it, thanks!! at least no compile errors. I’m not ‘bleeding edge’ in terms of flex and want to get your Twitter library working in Flexbuilder3, as3 only. So I assume I at LEAST need the 3 following
1-your Twitter package at com.soenkerohde.twitter
2-as3corelib.swc
3- Your OAuth package at flaircode.oauth (I need to modify OAuthLoader since it references mx.core.UIComponent)
But not sure about the oauth-as3.swc which contains the com.hurlant and org.iotashan packages.
Will this swc work for a Flexbuilder3, AS3 only project?
Am I missing something?
Thanks again for a great resource!
The example is made for Flex 4 so I would encourage you to try out Flash Builder 4 beta 2.
Then you only need to compile my twitter lib and add the swc to the project.
Sorry, but don’t have the time to run you through with Flex 3.
Sönke
Got it working AS3 only!
Again, thanks, your example is really awesome!
Great work Sönke;
Are you planning to develop your Twitter class further by adding more functionality?
Thanks, I would really like to build more but don’t know when I will have time for it.
But since it’s open source go ahead and fork it 😉
I have been playing around with your code as a web app rather than air and keep getting a Security Error when calling for the request token. Only happens when in side the browser and not when in standalone flash player.
Any ideas why this might be happening?
Scooty, sorry I never tried a web app so if you have a fix for it I would be happy to integrate it in the source.
Looks like using the OAuth API is not possible for web apps with Security.sandboxType of remote unless Twitter change their crossdomain policy file.
Regarding web apps again here is the info
http://groups.google.com/group/twitter-development-talk/browse_thread/thread/5cfc09a253cefc3b/27266b02fc2277e4?lnk=gst&q=policy+file#27266b02fc2277e4
I need to make a web app that works like this AIR app. Is it conceivable that this code could be merged with a ‘tweetr’ like crossdomain policy workaround? (http://tweetr.swfjunkie.com/docs/com/swfjunkie/tweetr/Tweetr.html) If so, how would I go about doing that.
I would like to try this example but I have no idea where to down load these classes — import com.soenkerohde.twitter.* Can you tell me where to download them?
Thank you for sharing this example.
Sure, the source is on github: http://github.com/srohde/Twitter
Hey Sonke,
Helpful lib, thanks! I wasn’t too keen on popping open a browser and forcing the user to manually enter a pin, so I made a few tweaks and got it working within Air.HTML making it more seamless. *Note that on Twitter, you must change the application type to Browser rather than Client.
I forked and pushed my changes here: http://github.com/shi11/Twitter
and posted an example here: http://gist.github.com/476155
Seth
Very cool, thanks for letting me know.
I had this build in too and removed it because I thought users might wanna only enter their credentials when they see that they are actually on the Twitter homepage.
Otherwise you could fake the HTML and get access to the users password. Maybe a bit too paranoid but anyways.
hi ,
m not able to use your app in my flash web app,actually its throughing an error because m not able to include ur org package…how to include it?
[…] AS3 OAuth Lib with Flex 4 example: http://soenkerohde.com/2010/01/twitter-as3-oauth-lib-with-flex-4-example/comment-page-1/ […]
[…] AS3 OAuth Lib with Flex 4 example: http://soenkerohde.com/2010/01/twitter-as3-oauth-lib-with-flex-4-example/comment-page-1/ […]
Hi,
I am trying to use your Test app and I can authenticate successfully, but when I try to post a status update I always get prompted with a ‘enter username/password’ dialog. It says that the server api.twitter.com Twitter API requires a username and password.
Could this be because of some security on the AIR side? But when I try to any GET methods it works fine. Seems the problem is only for POST methods.
Any clue? Anyone is able to use this example?
Hello,
I am also trying to get this working in Flex4 with AIR. This is what happens for me.
1. Run the app, browser opens asking for me to allow my app with twitter.
2. Click allow get a pin code.
3. Enter code in the app and press validate.
4. Enter a tweet and press send.
5. Username and password dialog pops up over app.
6. Enter credentials and get Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: https://twitter.com/statuses/update.json
Can you give it a test with AIR again please? Would really like to give this a go.
Cheers
@Neil
Yes the same exact thing happens for me too. What’s strange is that if you change the request URL to use GET, then it will work fine.
I tried the other OAuth AS3 lib available and it shows the same problem.
Thanks for the feedback.
It’s been a while and I have no time to debug this right now, sorry!
But since the change to GET seems to work why can’t you contribute a fix?
i know this is specifically to use oauth api to twitter .. but i’m assuming i can mod it to use it with any api?
Sure, Twitter was just an example.
thanks. 😀 huge help bro.. will definitely u updated on my project.
[…] ↑をベースとしてTwitterのOAuth認証に特化したライブラリ http://soenkerohde.com/2010/01/twitter-as3-oauth-lib-with-flex-4-example/ […]
Hi, thanks for the great code, but there’s still one problem i can’t solve. I’ve made your example work for a Web project locally, but everytime i try to log-in i’ll get a Sandbox Violation Error, thrown by the Twitter class authenticate method. Looking at the twitter crossdomain.xml file http://twitter.com/crossdomain.xml, it appears that this is simply not possible, as the only allowed domain is twitter itself, what would make the API almost useless, do you know any workaround for this, have you faced this problem ?
Thx !
-lucas
Lucas, sorry I always used AIR so I don’t know what to change to make it work from the web.
@lucas
Checkout this – http://wiki.swfjunkie.com/tweetr:howtos:installing-the-proxy
it says you should use a proxy when using twitter api for flash in a browser environment.
it also has a flash tutorial – http://blog.swfjunkie.com/2010/08/tweetr-v1-0b3-out/.
Good luck.
My AIR app got a username / password prompt for which no password worked. When I pressed cancel, an IOError occurred. I was never able to send an update.
[…] OAuthRequest. But when we’re using POST instead of GET, things have to be done differently. Soenke Rohde has a Flash Twitter library that I used for help, but essentially we have to strip the URL params from the original request and […]
This works fine as well in AIR on Android but you have to include the oAuth version in the SET_STATUS for it to work on a device (tested running Android 2.2 on HTC Desire):
public static const SET_STATUS:String = “https://api.twitter.com/1/statuses/update.json”;
Im having problems with updating the status…
Everything works great until i type something and hit send.
Here is the error message i am getting. I tried changing the SET_STATUS to what peter mentioned, and that did not help.
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: https://api.twitter.com/1/statuses/update.json?oauth_consumer_key=HRAqoQqy2WOAV6ffwLsbHg&oauth_nonce=9FE255CF-3F96-10B0-4441-5A3039228A5E&oauth_signature=ZWqOnsZTM5Vo8i1eKccSWIks2js%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1302888200&oauth_token=257943893-wkE8iW55zlLAfm2tIAur7AmbDtjNQquyl5dDU1Qe
at com.soenkerohde.twitter::Twitter/setStatus()[/Users/ondagaskiknass/Desktop/Sprint1/twitter/src/com/soenkerohde/twitter/Twitter.as:143]
at twitter/statusClickHandler()[/Users/ondagaskiknass/Desktop/Sprint1/twitter/src/twitter.mxml:111]
at twitter/___twitter_Button2_click()[/Users/ondagaskiknass/Desktop/Sprint1/twitter/src/twitter.mxml:168]
Thank you so much for this example. Our development team just got denied permission to use xAuth, so this greatly helped us get Twitter working in our app! I will reblog this once my website is finished!
PIN? What’s my pin?
I was getting the unhandled ioError, as well. I wrote an ioError handler and found through the loader data that I was getting rejected by Twitter. I changed three things:
1) My token was old. I added a button to the app that had a handler that cleared the shared object that required re-authentication to obtain a new token.
2) Twitter rejected my authentication. It appeared that the api requirements had changed a little bit and the url string required oauth_version, (&oauth_version=1.0) at the end of the string.
3) My app didn’t have permission to post. I had to go into my application settings at the twitter dev site and change my app permission from “read-only” to “Read, Write, and Access Direct Messages.”
After making those changes and waiting a few minutes for them to take effect, it worked for me. I’m not sure if the version # change made a difference or not, but that’s what I did.
[…] Sonke Rhode’s OAuth example – I’m using this example with the others to complete the authorization calls […]
thx great script
i have suc6 mod with in_reply_to_status_id and wrap_links.
but i having troubles with POST statuses/update_with_media (https://dev.twitter.com/docs/api/1/post/statuses/update_with_media) > media.
thx
have anyone done a tweet with a photo??? if someone can me or pass an url with tips/example
Extremely helpful writeup! Real life save for me.
I was getting 2032 Stream Errors, but request.url += “&oauth_version=1.0”; did the trick
Thanks to Bryan for that post or I would’ve been stuck!
Can’t get it to function, I keep getting a stream error..
Where and how should i add the request.url+= “&oauth_version=1.0”;?
For now I’ve added it straight into the getParameters function like this:
for (var param:String in _requestParams) {
aParams.push(param + “=” + URLEncoding.encode(_requestParams[param].toString()));
}
aParams.push(“oauth_version=1.0”);
Any chance this article might get an update?
Donny, sorry, but I don’t have time to work on an update.
Pretty nice post. I simply stumbled upon your blog and wanted to say that I have really loved surfing around your weblog posts. In any case I’ll be subscribing for your rss feed and I hope you write once more very soon!
please… can anyone who is getting the 2032 error, and successfully fixed it… outline what they did
Sorry for the false lead guys, actually adding “oauth_version” didn’t help, I’m still getting a 2032.
This sucks, this whole lib is basically useless because of this mysterious error
Sorry for that, haven’t looked at that code for a very long time.
[…] http://soenkerohde.com/2010/01/twitter-as3-oauth-lib-with-flex-4-example/ http://www.iotashan.com/index.php/2008/04/28/oauth-actionscript-library/ […]
The code from this website solved the “Error #2032”
https://github.com/xtyler/tweetr/downloads
Thanks.
To bad with the 2044 error… Looks promising!
No one has a good fix?