Hello everyone,

I have problems to use xAuth in a own Twitter application. I have
register an Application and was activated for xauth. I have develop an
Adobe AIR Application which used ActionScript 3.0. In addition, I use
the ActionScript 3 library for oAuth, which is refer in the Twitter
docomentation for ActionScript developers. (http://code.google.com/p/
Unfortunately I can not get a successful response from the twitter
server. I would describe you to my approach and I hope that everyone
can give me a help.

At first time, I create my parameters. For this I used the
"OAuthRequestClass" from the oauth-as3 library. This class, I have
added the xauth parameter. In the following a Code-snipped:

                        var curDate:Date = new Date();
                        var uuid:String = UIDUtil.getUID(curDate);

                        _requestParams["oauth_consumer_key"] = _consumer.key;
                        _requestParams["oauth_consumer_secret"] = 
                        _requestParams["oauth_nonce"] = uuid;
                        _requestParams["oauth_signature_method"] = 
                        _requestParams["oauth_timestamp"] =
String(curDate.time).substring(0, 10);
                        _requestParams["oauth_version"] = "1.0";
                        _requestParams["x_auth_mode"] = "client_auth";
                        _requestParams["x_auth_password"] = password;
                        _requestParams["x_auth_username"] = user;

                        _requestParams["oauth_token"] = _token.key;
                        _requestParams["oauth_token_secret"] = _token.secret;

                        // generate the signature
                        var signature:String = 
                        _requestParams["oauth_signature"] = signature;

The Signantur is determined by the following function throw the class
"OAuthSignatureMethod_HMAC_SHA1" from the oauth-as3 library:

                public function signRequest(request:OAuthRequest):String {
                        // get the signable string
                        var toBeSigned:String = request.getSignableString();

                        // get the secrets to encrypt with
                        var sSec:String = 
URLEncoding.encode(request.consumer.secret) + "&"
                        if (request.token)
                                sSec += 

                        // hash them
                        var hmac:HMAC = Crypto.getHMAC("sha1");
                        var key:ByteArray = Hex.toArray(Hex.fromString(sSec));
                        var message:ByteArray = 

                        var result:ByteArray = hmac.compute(key,message);
                        var ret:String = Base64.encodeByteArray(result);

                        return ret;

In the variable "toBeSigned" is included my OAuth signature base

Additionally, I have at this point trying to use the parameters
oauth_consumer_secret and oauth_token.

In my variable "aSec" is including. "myConsumerKey+"&"+myOAuthToken".

For the variable "aSec" I have test following combinations:

Since the Twitter documentation to the oauth-as3 library reference, I
assume that runs the encryption correctly.
Perhaps at this point but made a mistake. Can everyone encrypt one
time the words "hello", "world" and tell me how this would look like
encrypted, which is also in use xauth? My result after the above code
would look like: ijqEvNDQBl6X8XXTcER8fQLgCXM=

After this I create my OAuth HTTP Authorisation header. The header
name is "Authorization" and the header value is the following:
OAuth oauth_nonce="5653B8B9-87E3-89DA-3857-1E9E70C56F5C",
oauth_signature_method="HMAC-SHA1", oauth_timestamp="1284708921",
oauth_signature="...myCreatedSignanture...", oauth_version="1.0"

I send a Request with this url to the twitter server:

In the following

In the following my ActionScript code by I make my request to your

                                var postVariables:String = "?

                                var params:URLVariables = new URLVariables();
                                params.x_auth_mode = "client_auth";
                                params.x_auth_password = password;
                                params.x_auth_username = user;

                                var request:URLRequest = new 

                                request.method = URLRequestMethod.POST;
                                request.requestHeaders = new Array(header);
                                request.contentType = 
                                //request.data = params;

                                var loader:URLLoader = new URLLoader();

Unfortunately I do not get an successful response. I get the Error-
Message "Failed to validate oauth signature and token", the HTTP
status code 401 and following Error-description:
"Error #2032: Stream Error. URL:

I am grateful for any help

Twitter developer documentation and resources: http://dev.twitter.com/doc
API updates via Twitter: http://twitter.com/twitterapi
Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list
Change your membership to this group: 

Reply via email to