Problem:
Your AIR application needs to validate the username / password and handle failure gracefully within the application. If the user enters the wrong information you do not want them to be prompted with a windows prompt asking them to enter their Twitter username / password. If the application needs to hold on to the credentials for any reason the windows authentication to the API will break the AIR application.
“The server twitter.com at Twitter API requires a username and password.”
Solution:
The URLRequest object has a property called ‘authenticate’ that must be set to false.
/** * * Setting result.authenticate to false prevents the operating system from * taking over and prompting the user to authenticate. It allows the AIR * application to take the correct action. * */ private function twitterRequest (url : String):URLRequest { var result:URLRequest = new URLRequest (url); if (this.authorizationHeader){ result.authenticate = false; // <--------- Most Important Line of Code!!!! result.requestHeaders = [this.authorizationHeader]; } return result; }
Most of the code from the example attached below is from the Google code repository:
http://code.google.com/p/twitterscript/
Here are the source files to an example AIR application that uses actionscript to verify Twitter credentials without prompting a windows box on failure:
I would like to give credit to Clayton (file_cabinet) for coming up with the solution to this problem. Thanks Clayton!
This is precisely what I was looking for. I was hoping to use mx:HTTPService to do this for me. Think that’s possible?
Hmm… I am not sure off the top of my head if HTTPService will work for this since there is a bunch of code I am using from the AS3 Twitter API. Let me know if you find anything. If I come across a solution using HTTPService I will defiantly post it here and forward it to your e-mail. Thanks for the feedback!
Cheers,
Chris
Thank you!
I’ve been trying to figure this out for the past 4 hours…
Thanks for sharing this lifesaver, it works great!
I’m having this problem and I’m excited to find a solution, but where do I put the files? Do I just extract them to my main directory and it’ll automatically work? Thank you!
To get the source files up and running. Download the source zip, open up Flex builder 3 than click on ‘file->import->Flex Project…’ Select the zip file for the archive path and click finish. Everything needed for the demo is in the source zip so you should be good to go from there.
Cheers, Chris
Great !!! Thanks for posting the solution to this, I just spent one hour trying to figure this out.
Cheers, Enrique