Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Twitter xAuth issues

Hi All,
Bit long winded this one.

With the help of this post: (http://developer.appcelerator.com/question/4581/custom-module) I've managed to successfully get oauth_token and oauth_token_secret using xAuth (not oAuth).

However when I come to use these tokens to use Twitter API, I get the following error:

{"source":{},"type":"error","error":"Error Domain=ASIHTTPRequestErrorDomain Code=3 \"Authentication needed\" UserInfo=0x7c40390 {NSLocalizedDescription=Authentication needed}"}

If I get the final oauth URL out that has been built up, and then stick it into a browser I ended up getting Invalid / Used Nonce, error. Googling this seems to say its not an actual Nonce error.

If I then remove the oauth_signature from the url and enter my username and password into the browser, I get the json/xml.

So it looks like the oauth_signature is being created incorrectly. I've looked at the timestamp, and it's fine.

Has anyone actually got this working using xAuth. It should be so simple, yet it's doing my head in.

Here's some of my code:

> This works: xauth_adaptor.js http://pastie.org/1098503

> This doesn't: functions.js http://pastie.org/1098506

My loginTwitter() function is called from a login window in my app.js. This succesfully logs in, but when it calls the function from functions.js I get the error.

Any help would be gratefully appreciated. I don't really want to go down the oAuth route and having to open a webview, when xAuth is supposed to be meant for mobile development

— asked August 17th 2010 by Paul Pounder
  • twitter
  • xauth
0 Comments

4 Answers

  • Accepted Answer

    I think the problem is your are using readystate to trigger send data function before onload function done parsing.

    Take out the readystate logic completely (49-63), put that on onload and trigger user timeline after you successfully parsed the tokens. That's how i did it.

    BTW, readystate 200 only means the XHR request successfully and ready, not the positive result of responsetext, you shouldn't trigger get timeline function on that anyway.

    — answered August 17th 2010 by Daniel Lim
    permalink
    0 Comments
  • Hi Paul, mine is working just fine with Xauth. However, i only use it to share (post update) and not pulling timeline. what version of Ti you are using? Early built 1.4 has issue with escaping URL querysting.

    Regarding the Json format, i suppose you can define that on parameters such as

        var message = {
            method: "POST",
            action: requestUrl,
            parameters: [
                ['oauth_signature_method', 'HMAC-SHA1'],
                ['oauth_consumer_key', xauth.consumerKey],
                ['oauth_version', '1.0'],
                ['oauth_token', Twitter.getSetting().Twitter_xt],
                ['format', 'json'],
                ['status',data.text]
            ]
        }
    
    — answered August 17th 2010 by Daniel Lim
    permalink
    0 Comments
  • Hi Daniel,

    I do actually get the same error on a sendTweet function that I used from Kosso's reply on this page: http://developer.appcelerator.com/question/4581/custom-module

    I am using a build version of 1.4.1 from last week, which has the escape character resolved.

    I can actually authenticate, but not do anything with the API after this, if I could get the sending a tweet function working I'm sure I could get the pull timeline working. I'm now wondering whether even though I'm authenticating, maybe I'm not correctly.

    Are you able to share your xAuth authenticate and send status functions?

    Kind regards
    Paul

    — answered August 17th 2010 by Paul Pounder
    permalink
    0 Comments
  • Hi Daniel,

    If I could buy you a beer I would. That was exactly the issue. I was sending data over before it had properly authenticated.

    Many many thanks

    Paul

    — answered August 18th 2010 by Paul Pounder
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.