My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
UsageManualR4  
How to use the OAuthAdapter release 4.
Phase-Deploy
Updated Jul 20, 2010 by ziod...@gmail.com

Introduction

This short introduction will explain how to use the OAuthAdapter.

Download the oauth_adapter.js file according to your version of Titanium Mobile SDK and iPhone SDK:

You need to download the following two libraries to a lib subfolder (below the Resource folder) in your project:

Then download the oauth_adapter.js in any folder you like and include it via Ti.include('oauth_adapter.js').

Details

var oAuthAdapter = new OAuthAdapter(
	'<your-consumer-secret>',
	'<your-consumer-key>',
	'HMAC-SHA1');


// load the access token for the service (if previously saved)
oAuthAdapter.loadAccessToken('twitter');

oAuthAdapter.send('https://api.twitter.com/1/statuses/update.json', [['status', 'hey @ziodave, I successfully tested the #oauth adapter with #twitter and @appcelerator #titanium!']], 'Twitter', 'Published.', 'Not published.');

// if the client is not authorized, ask for authorization. the previous tweet will be sent automatically after authorization
if (oAuthAdapter.isAuthorized() == false)
 {
    // this function will be called as soon as the application is authorized
    var receivePin = function() {
        // get the access token with the provided pin/oauth_verifier
        oAuthAdapter.getAccessToken('http://twitter.com/oauth/access_token');
        // save the access token
        oAuthAdapter.saveAccessToken('twitter');
    };

    // show the authorization UI and call back the receive PIN function
    oAuthAdapter.showAuthorizeUI('http://twitter.com/oauth/authorize?oauth_token=' +
        oAuthAdapter.getRequestToken('http://twitter.com/oauth/request_token', [['oauth_callback', 'oob']]),
        receivePin, PinFinder.twitter);
}
Comment by vpapakon...@gmail.com, Jul 2, 2010

Do we need to include something like:

Ti.include('lib/oauth_adapter.js');

Using the code I get to the authorization screen, I enter the credentials and press "yes" to authorize. Then the window closes and the app crashes. Sometimes before the app crashing I get to see the "code". What am I doing wrong?

Comment by jspear...@gmail.com, Jul 5, 2010

Same problem for me on an iPad app, using TI 3.1.2 and R4.

Most times the application will simply exit without throwing an error, but when it does throw an error it is as seen at:

http://pastie.org/1031109

Hope this helps.

Jim

Comment by jspear...@gmail.com, Jul 5, 2010

Update: This also happens on an iPhone App, TI: 3.1.2, R4, iOS4

Comment by project member ziod...@gmail.com, Jul 5, 2010

Hi vpapakonstantinou,

The simulator might crash before of the following issue: app-crash-on-textarea-in-13-with-error-webtrythreadlock

Let me know if it's the one you're experiencing.

Comment by project member ziod...@gmail.com, Jul 5, 2010

Hi jspearson,

Try the sample iPad app here: http://bit.ly/cfLTRa. You might want to adjust width and height of the Authorization UI.

David

Comment by larre...@gmail.com, Jul 9, 2010

This gets as far as showAuthorizeUI and that results in the twitter 404 page. Anybody else having the same problem?

Comment by project member ziod...@gmail.com, Jul 9, 2010

Hi Larrence,

Thanks for trying out the oAuth Adapter. According to this log line, you didn't set your consumer key and secret. Remember to get them from Twitter: INFO? Creating a message [{"action":"http://twitter.com/oauth/request_token","method":"POST","parameters":[["oauth_consumer_key","<my consumer key>"],["oauth_signature_method","HMAC-SHA1"],["oauth_callback","oob"]]}]: done.

David

Comment by larre...@gmail.com, Jul 9, 2010

Actually I did, but I changed that line because I didn't want to post it here. I will look into it further. Thanks David.

Comment by ther...@gmail.com, Jul 17, 2010

Is it possible to use it with Facebook?

Comment by project member ziod...@gmail.com, Jul 17, 2010

Hi Therium, hadn't got the chance to test it with Facebook.

Comment by ther...@gmail.com, Jul 17, 2010

I found a bug in the newest release, when I want to sign in with Twitter the webView opens, then when I start to type the keyboard slides up and all the views behind the webView also slideup.

Comment by annakozy...@gmail.com, Jul 20, 2010

The crash with -setHref:?: unrecognized selector sent to instance 0x7d5a820 also happens to me

Comment by project member ziod...@gmail.com, Jul 20, 2010

if you're using iPhone SDK 4, there's a bug with the WebView? trying to recognize the phone numbers in the web page and crashing.

R14 of the OAuth Adapter disables this behaviour, you can get it here:

http://oauth-adapter.googlecode.com/svn-history/r14/trunk/oauth_adapter.js

Let me know if it helps

Comment by annakozy...@gmail.com, Jul 20, 2010

Got it. The crash is caused by some bug, that happens during the redirect of webView (has nothing to do with callbacks, it's a pure appcelerator bug). If you upgrade appcelerator to the next version (1.3.2), the crash problem simply disappears

Comment by annakozy...@gmail.com, Jul 20, 2010

To ziodave: indeed, I was using SDK 4.0 and appcelerator 1.3.0, and it was crashing. But I was ALREADY using the version R14, I think (this one: http://oauth-adapter.googlecode.com/svn-history/r14/trunk/oauth_adapter.js). Anyway it was crashing, and as much as I could tell, it was crashing in the moment of redirect by twitter (maybe they use some special redirect?)

Upgrade to 1.3.2 resolved the crash problem.

Comment by ther...@gmail.com, Jul 20, 2010

When I sign in and want to tweet I always get "Tweet not published". With R4 this problem didn't occur.

Comment by project member ziod...@gmail.com, Jul 20, 2010

Can you please always state which version of Titanium Mobile SDK and iPhone SDK are you using?

Comment by ther...@gmail.com, Jul 20, 2010

I found the problem, in the newest example you have: ['status': 'text'] but it must be [['status': 'text']]. That did the trick.

Comment by annakozy...@gmail.com, Jul 20, 2010

Please, I am quite new to twitter, how am I supposed to do sign out?

Comment by project member ziod...@gmail.com, Jul 20, 2010

There is not sign-out in OAuth processes. The user can de-authorize the access-code via the service pages. You don't need to implement anything for sign-out.

Comment by annakozy...@gmail.com, Jul 20, 2010

I do need to sign out to be able to relogin as a different user.

However I did figure it out:

oAuthAdapter.send("https://api.twitter.com/1/account/end_session.json",[],"Twitter", "Signed out!","Failed to sign out!");

var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'twitter.config'); file.deleteFile();
oAuthAdapter = new OAuthAdapter(
'secret', 'key', 'HMAC-SHA1');
oAuthAdapter.loadAccessToken('twitter');
Comment by project member ziod...@gmail.com, Jul 20, 2010

Yep, that's good :-)

Comment by annakozy...@gmail.com, Jul 20, 2010

One more thing, it's something simple, but I would suggest to let the user disable the error and success alerts (when empty text is passed, for example, no need to show empty alert). Just in many (if not most) cases the application has its own method of error-processing.

Comment by g...@thoughtcraft.com, Jul 30, 2010

Has anyone gotten this running on the Android emulator? I'm trying it and always see the Twitter 404 page. I'm assuming this is due to not receiving anything back from getRequestToken()... I see the debug message "request token got the following response: " with no value for client.responseText.

So as a first step I've been trying to get just getRequestToken() to work, with no luck - I tried both the https and http URLs for api.twitter.com/oauth/request_token, but same result in both cases, no data and client.status returning 0.

Any clues? My next step is to try through a network monitoring proxy to see exactly what's being generated, but I figured I'd ask here to see if anyone had had success with this first.

Comment by g...@thoughtcraft.com, Jul 30, 2010

OK, network proxy shows me that I'm getting a 401 Unathorized back from Twitter - so there's apparently something wrong with the Android/Titanium HTTPClient in that it's returning 0 for status. I'll raise that with the Titanium guys.

As for the OAuth stuff, my request looks like this:

-- BEGIN

POST /oauth/request_token HTTP/1.1 X-Requested-With: XMLHttpRequest User-Agent: Length: 76.0 Content-Length: 994 Content-Type: multipart/form-data; boundary=cbYfn0CWb2kprbwOkAbL1iJfS10jkCpWIyrC Host: api.twitter.com:7667 Connection: Keep-Alive

--cbYfn0CWb2kprbwOkAbL1iJfS10jkCpWIyrC Content-Disposition: form-data; name="oauth_signature" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit

UQc+zoYzZfMGg9y8IHZ7aB+p/gU= --cbYfn0CWb2kprbwOkAbL1iJfS10jkCpWIyrC Content-Disposition: form-data; name="oauth_nonce" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit

sRxe7D --cbYfn0CWb2kprbwOkAbL1iJfS10jkCpWIyrC Content-Disposition: form-data; name="oauth_consumer_key" <...etc...>

-- END

Does this look right? I'm new to OAuth, so am wondering if indeed the consumer_key, nonce, etc, should be sent as multipart-form-data...?

(thanks in advance for any tips/advice!)

Comment by mfsmil...@gmail.com, Aug 3, 2010

I cannot get this to work...I keep getting expressionBeginOffset = 2735; expressionCaretOffset = 2744; expressionEndOffset = 2744; line = 120; message = "Can't find variable: PinFinder?"; name = ReferenceError?; sourceId = 260345336; sourceURL = "file://localhost/Users/HD/Library/Application%20Support/iPhone%20Simulator/4.0/Applications/9CEE1941-7D1E-48EC-8DD9-778B12D1C74E/twitter.app/result.js"; } Any ideas??

Comment by s.w.har...@gmail.com, Aug 6, 2010

@mfsmillie, if you're using R16 you need to remove the reference to PinFinder?, look at the docs inside the .js file, not on this page.

However, having done that myself it crashes the app when it tried to authorise (the broswer briefly ends up at what looks like a 404 page sometimes, before it crashes.

Comment by s.w.har...@gmail.com, Aug 6, 2010

Should have added, I'm using Mobile SDK 1.4.0/1 and iPhone SDK 4.0.

Comment by carlssp...@gmail.com, Aug 17, 2010

same Error that s.w.harris have.

I'm using Mobile SDK 1.4.0 and iPhone SDK 4.0

Any help?

Comment by carlssp...@gmail.com, Aug 17, 2010

Here is the Solution:

Edit the Line:

oAuthAdapter.showAuthorizeUI('http://twitter.com/oauth/authorize?oauth_token=' +
oAuthAdapter.getRequestToken('http://twitter.com/oauth/request_token', [['oauth_callback', 'oob']]), receivePin, PinFinder?.twitter);

In:

oAuthAdapter.showAuthorizeUI('http://twitter.com/oauth/authorize?' +

oAuthAdapter.getRequestToken('http://twitter.com/oauth/request_token', [['oauth_callback', 'oob']]), receivePin);

Thats all an it works for me

Comment by x3c...@gmail.com, Aug 22, 2010

I get this error message when use oauth_adapter_r16

[DEBUG] Loading access token for service [twitter].
[DEBUG] Sending a message to the service at [https://api.twitter.com/1/statuses/update.json] with the following params: [["status","Hey @ziodave, I managed to use the #oauth adapter for @titanium consuming @twitterapi"]]
[DEBUG] The send status cannot be processed as the client doesn't have an access token. The status update will be sent as soon as the client has an access token.
[DEBUG] request token got the following response: null
[DEBUG] Setting:[0]
[DEBUG] authorizeUILoaded

And when debug, I see this error occur due to

var contents = file.read(); //line 117
if (contents == null) return; // line 118

Because file .config exists, but its content is null, so my program cannot read config of this contents.

I'm using Mobile SDK 1.4.0 and iPhone SDK 4.0.

Anyone can help me?

Comment by AdemarTu...@gmail.com, Aug 28, 2010

does this work with android? are there major conflicts if we us it on android?

Comment by jeroen.v...@gmail.com, Sep 20, 2010

Using Mobile SDK 1.4.1 and iPhone SDK 4.0 having problems with my apps crash after the oAuth popups shows.

After some debugging I found that the problem is with:

var xmlDocument = Ti.XML.parseString(e.source.html);

in the authorizeUICallback function.

Terminating app due to uncaught exception 'org.sometestapp.TiDOMDocumentProxy', reason: 'Error Domain=com.google.GDataXML Code=-1 "The operation couldn’t be completed. (com.google.GDataXML error -1.)". in -parseString:? (TiDOMDocumentProxy.m:50)'

Comment by ranacs...@gmail.com, Oct 1, 2010

how to get the home_timeline ? I'm not good with JS so please someone help me .

Comment by acarlos1...@gmail.com, Oct 4, 2010

I am seeing the same eeror as @jeroen.van.wissen After the oAuth Pop shows up, the app crashes.

Any tips

Comment by ali.r.f...@gmail.com, Oct 6, 2010

I'm in the same boat as @AdemarTutor? and g...@thoughtcraft.com - can someone recommend some way to get this working with Android? I'm getting the 404 error page from Twitter also. What needs to be changed in the adapter or in the Titanium SDK to get this working for Android? I noticed X-Request-Header is not being set for twitter.com in the SDK.

Comment by raj...@gmail.com, Oct 8, 2010

I have the same problem as well, it opens up a 404 and then crashed. Anybody has an answer would greatly be appreciated :)

Comment by raj...@gmail.com, Oct 8, 2010

Ahh ok my bad, followed @carlsspace solution and it worked.

But I have another problem, it doesn't seem to work with GET. I'm trying to call statuses/home_timeline and it's not working, it says 401 and the connectionType is still POST no matter what I do :(

Comment by kellyre...@gmail.com, Oct 24, 2010

wow, just found this and it looks awesome...is this solely for twitter? i'm trying to add dropbox functionality to my ipad app and have been looking for an oauth solution. not really familiar with this or oauth enough to know if i can tweak it for dropbox. can anyone tell me if its possible? thx!

Comment by contact%...@gtempaccount.com, Oct 27, 2010

@carlsspace solution works perfectly for posting. everyone refer to that who is having problems with the "404 app crash" bug

Comment by poloma...@gmail.com, Nov 4, 2010

I'm using this to connect with the FreshBooks? api... buggy since it only supports twitter but I'm making progress.

FreshBooks? requires that the oauth_callback be explicitly set... anyone have any ideas on how to handle this since freshbooks passes a oauth_verifier and oauth_token parameter to the callback url?

Also, there is no "pin" with FreshBooks?... just show the login view for user to input freshbooks username/pw on the FB server

Comment by poloma...@gmail.com, Nov 5, 2010

I've been able to get the oauth verification to work with FreshBooks?.. anyone have any idea how to post XML with this library?

Comment by tho...@gmail.com, Nov 7, 2010

Hi, I've finally managed to have it work in my titanium project, but i'm wondering one thing : how can I retreive the username ? I'd like to display the user time line, but I can't grab the username specified during the registration process. I've tried with a listener set on the webview, parsing the DOM while the user is entering it, but it's not working.. Did I missed something ?

Comment by mfitu...@gmail.com, Nov 14, 2010

Here are some bugfixes. This makes it compatible with the SDK 1.4.1.1 and above. In addition, this fixes the problem of non-compliant XML from Twitter. http://pastie.org/1297119

Comment by planetab...@gmail.com, Nov 25, 2010

This worked for me:

Ti.include("oauth_adapter.js");

var oAuthAdapter = new OAuthAdapter(

'YOU KNOW', 'YOU KNOW', 'HMAC-SHA1');

oAuthAdapter.loadAccessToken('twitter');

//oAuthAdapter.send('https://api.twitter.com/1/statuses/update.json', [['status', 'Test :)']], 'Twitter', 'Published.', 'Not published.'); if (oAuthAdapter.isAuthorized() == false)

{
// this function will be called as soon as the application is authorized var receivePin = function() {
// get the access token with the provided pin/oauth_verifier oAuthAdapter.getAccessToken('https://api.twitter.com/oauth/access_token'); // save the access token oAuthAdapter.saveAccessToken('twitter');
};
// show the authorization UI and call back the receive PIN function oAuthAdapter.showAuthorizeUI('https://twitter.com/oauth/authorize?' +
oAuthAdapter.getRequestToken('https://api.twitter.com/oauth/request_token', 'oob'), receivePin);
}

Comment by thekingf...@gmail.com, Dec 14, 2010

it was working but now i keep getting "Sorry,that page doesn't exist" what is wrong ???

Comment by mfitu...@gmail.com, Dec 14, 2010

Same issue here.

Comment by thekingf...@gmail.com, Dec 14, 2010

thanks @planetabinari worked just fine

Comment by sergej.k...@gmail.com, Dec 15, 2010

Wondering too, also getting "Sorry, that page doesn't exist". So many different versions out there now of the oauthadapter code and the integration code. If someone could just make one "this is the official latest working version"-doc that would be super-awesome! :)

Comment by ali.r.f...@gmail.com, Dec 15, 2010

This definitely doesn't work with Titanium SDK 1.5.0. I just ran it with Titanium SDK 1.4.2 and it worked. Getting the 404 "Sorry this page doesn't exist" page from Twitter and then my app crashes with 1.5.0. Looks like a change Titanium made causes this to break.

Comment by Akseno...@gmail.com, Dec 16, 2010

Same problem here, stopped working with Titanium SDK 1.5.0 Any solutions?

Comment by dnal...@gmail.com, Dec 19, 2010

How it worked for me with Titanium 1.2x and up

Yes at first I tried it and had the same complaints about errors mentioned in the comments above. So after a night of rest checked it all out again. It appears I made the following mistakes:
  • swapped consumer-key and consumer-secret entries at the var oAuthAdapter= new OauthAdapter(...)
  • Be sure to set your oAuth application's Application Type settings on the Twitter Development portal to the 'Client' type instead of regular/default 'Browser' type for your app

That's about it!

I run Titanium 1.2.1 against iPhone SDK 3.1.2 or so. Still need to update to Snowleopard for SDK 4 support :)

For another app 'Shoudio - location based audio recordings' I do the oauth stuff by having an intermediate usersystem on the mobile site and doing the FB & Twitter oauth connections through a webview

How it stopped working for me with Titanium 1.5.0 / 1.5.1 and up

When I test on the laptop against Titanium 1.2.x it works, but on an iOS4 device with Titanium 1.5.1 Twitter keeps returning the 'that page does not exist'

Same problem as reported by ali, sergej & aksenovdm

Comment by dnal...@gmail.com, Dec 20, 2010

Here is how I got it working with Titanium 1.5.1

Ok so here we go: I have Titanium 1.5.1 running against a iPhone SDK 3.1.x.

At first I also got the '404 page not found at Twitter' and some other errors, but with this current setup it all started working magically:

I use the following code block to call the Twitter API:

Ti.include('lib/oauth_adapter.js');
			
			var oAuthAdapter = new OAuthAdapter(
	        'YOUR_CONSUMER_SECRET_HERE',
	        'YOUR CONSUMER KEY HERE',
		    'HMAC-SHA1');


			// load the access token for the service (if previously saved)
			oAuthAdapter.loadAccessToken('twitter');
			
			oAuthAdapter.loadAccessToken('twitter');
			
			oAuthAdapter.send('https://api.twitter.com/1/statuses/update.json', [['status', '@shoudio retoric testing is epic. This random number too right? '+Math.random()]], 'Twitter', 'Published.', 'Not published.'); 
			
			if (oAuthAdapter.isAuthorized() == false) 
			{
			// this function will be called as soon as the application is authorized 
			var receivePin = function() {
			// get the access token with the provided pin/oauth_verifier
			 oAuthAdapter.getAccessToken('https://api.twitter.com/oauth/access_token'); 
			 // save the access token
			  oAuthAdapter.saveAccessToken('twitter');
			};
			// show the authorization UI and call back the receive PIN function 
			
			oAuthAdapter.showAuthorizeUI('https://api.twitter.com/oauth/authorize?' +
			oAuthAdapter.getRequestToken('https://api.twitter.com/oauth/request_token'), receivePin);
			}

As you might notice in the code block above I added a 'Math.random()' to the test Tweet to post, because otherwise after one test, you will get the 'Not published' error, because you are sending out duplicate tweets.

I hope this helps somebody. I will implement this in V2 of Shoudio

Comment by ashwinir...@gmail.com, Jan 5, 2011

How to post an image as a tweet using this code.

Comment by ashwinir...@gmail.com, Jan 10, 2011

I am not getting a button to close in the appeared twitter ui. If i want to go back on my previous window what should i do??

Comment by Akseno...@gmail.com, Jan 26, 2011

Cannot get the close button in 1.5.1, any solution availabale for that?

Comment by klin...@gmail.com, Feb 2, 2011

I am running into a '404 page not found' error when trying to authenticate on Titanium 1.5.1 running against Android APIs 2.2. Seems that oAuthAdapter.getRequestToken is not returning a token but rather an massage saying the request was not valid.

Does anyone have a workaround or solution?

Thanks in advance for your help. Kelvin

Comment by maki.mik...@gmail.com, Feb 18, 2011

There are a fair number of issues with Titanium and Android, but I was able to get it working on 1.5.1. I can post a diff later, but essentially this is what I found:

  • Titanium.Network doesn't seem to work in synchronous mode in Android, had to modify the adapter to use callbacks instead of returns.
  • The number to string conversion for timestamps in client.send() went into float format, so Twitter couldn't recognize the timestamp. Put in a .toFixed(0) before it was sent.
  • webView.html does not get populated on Android, so used the work-around posted here: http://developer.appcelerator.com/question/102231/android-sees-tiuiwebviewhtml-as-undefined
  • Had trouble getting the source that was fetched with the work-around to parse in the XML utility, so I used a regex instead.
  • Als noticed that the regex on Android+Titanium doesn't seem to populate captures if there's more than one capture defined.

Comment by ghester%...@gtempaccount.com, Feb 20, 2011

@maki.mik do you think you could post your solution? I' am having the same problems and getting this to work in android is the last thing I need to do for my app...

Comment by exi...@gmail.com, Feb 21, 2011

@maki.mik great catch! hi @ghes, hope this helpes. http://www.exilis.org/uploads/0001-now-it-runs-on-Android.patch This is a patch for https://github.com/mogya/tm_twitter_api .

Comment by ghester%...@gtempaccount.com, Feb 21, 2011

Thanks @exi that was exactly what I was looking for!

Comment by exi...@gmail.com, Feb 22, 2011

@ges It seems there are bugs in my code. I'll submit another patch later...

Comment by yangua...@gmail.com, Feb 23, 2011

@ exilis, I tryed your patch for android,but seems did not work,do you know how to fix? Any help would be greatly appreciated.

Comment by exi...@gmail.com, Feb 23, 2011

I'm going to submit a new patch soon, but here is a list of fixes, just in case.

  1. It doesn't work with TitaniumMobile1?.5.1. You have to use the version which has https://github.com/appcelerator/titanium_mobile/commit/c84d12e41cedeba00f5fd825ca21fd evalJS() fix.
  2. In auth_adapter.js, you need window.open(); just after window.add(view); so that password confirmation won't show up behind the dialog after clicking 'Allow' link.
  3. In auth_adapter.js, I put some bugs in onerror handlers.
  4. twitter_api.js, init() needs to be fixed to handle async flow properly.
Comment by jas...@gmail.com, Feb 23, 2011

Thanks, @exi, for your work here. Do you know if the evalJS() fix is supposed to be in 1.5.2?

Comment by lazyco...@gmail.com, Feb 24, 2011

Just wanted to post some thanks for a great script.

I did notice that while the twitter oauth works completely fine with Titanium 1.6 and iOS 4.0 SDK, while trying the exact same code on Titanium 1.6 and iOS 3.2 SDK, I kept getting "Tweet not published" alerts.

Am I missing something to get it to work in 3.2? Or do you think that the changes in Titanium 1.6 Mobile SDK has broken it?

Comment by grantmar...@gmail.com, Feb 24, 2011

I have this working with some of the suggestions in Titanium 1.6 and ios 3.2 and above. One thing I am looking at is if you decide not to authorize the app via the twitter authorization page it doesn't close so your app is left with a hanging webview.

Comment by exi...@gmail.com, Feb 24, 2011

@grantmar Yes, you are right, window.hide() doesn't seem to work by some reason, but I found that setting .visible property works as a workaround. However, it crashes the process in another case... Another option is calling window.close() and which works as we expect, but the implication here is your callback function will never be called. I haven't have a chance to look into Titanium's code yet, but I would say this should be done by fixing Titanium side rather than patching oauth-adapter's interfaces.

http://bit.ly/fB41H7

Here is a link to my latest patch as just for your reference, but as I mentioned above, it has a problem of missing callback after showing the auth-ui. I haven't sent this patch to @mogya yet because I couldn't spend enough time for testing it past few days, and I'm going to be busy until March 6 for attending GDC. Thanks

Comment by alejandr...@gmail.com, Mar 4, 2011

I'm trying to run the oauth-adapter with no success. I have the following in my code http://pastebin.com/s8AJd3fg and I get this errors http://pastebin.com/xDA3JF2a when trying to send tweet.

When I click the button to send the tweet, I get to the authorizing window, after that I submit password and username, then it says authorization completed and it sends me to the webpage that I specify on developer.twitter.com, when it's loading the webpage the app crashes with the error http://pastebin.com/s8AJd3fg

Comment by alejandr...@gmail.com, Mar 4, 2011

Solved.. On Applications Settings in developer.twitter.com the Application Type has to be Client

Comment by josephdp...@gmail.com, Mar 18, 2011
[DEBUG] [15,14981] request token got the following response:
[DEBUG] [4,14985] Showing authorization UI [http://twitter.com/oauth/authorize?undefined].

So, there is no response being returned and when the UI opens it goes to a Twitter page saying "page not found" or the like.

Comment by jonathan...@gmail.com, Apr 3, 2011

Dear exilis, etc --

Just started following this thread. I am building an Android app using Appcelerator and would love to be able to use this OAuth adapter code. I worked through exilis' diffs (last one here: http://bit.ly/fB41H7) and still get the page not found error in my app.

Did anyone else get this to work on Android yet? And if so, would you mind posting the Android js implementation to this site? .js file much preferred over simple diffs if possible!

thanks all, appreciate your help, JB

Comment by guilo.gu...@gmail.com, Apr 8, 2011

I have tried with this one :

https://github.com/stereoket/oauth-adapter

But still I have That page doesn't exist.

But in LogCat? I can see that :

04-08 14:36:15.139: DEBUG/TiAPI(30278): (kroll$6: app://jobs_details.js) [2,24602] oauth_token=a_token&oauth_token_secret=a_different_token&oauth_callback_confirmed=true

Comment by i.r.tje...@gmail.com, Apr 18, 2011

I get 2 errors when posting the tweets.

Well the posing works, but I don't get the 'Close' button on the screen. Also when I click 'Deny' instead of 'Allow' i get redirected to a page (where i need the close button to close it, so I can't close it). When I click on a hyperlink on that page the app crashes also.

Has anyone had these problems too? I'm using Titanium SDK 1.6., iPhone SDK 4.2 and R16 of oauth.

Thanks!

Comment by esmo...@gmail.com, Apr 18, 2011

Has anyone definitively figured out the "this page doesn't exist" problem when running on a real device? I have this working perfectly in the iOS simulator under 4.3 or 4.2, but a 4.2 device(all i have to test with) shows the "does not exist" page instead of the login page.

Clueless...

Comment by i.r.tje...@gmail.com, Apr 29, 2011

Does anyones app crash with the new twitter authentication screen layout? Mine crashes on the moment it opens..

Any advice?

Comment by jgregmcc...@gmail.com, May 4, 2011

my app was just denied by the app store peeps because of twitter bug. Thing is, it looks like the twitter auth screen changed. I have an app with the exact same code that was working perfectly and was approved. Right before I submitted my new app to the app store things were great. I got a notice from them saying it was not working and that twitter was asking the user to write down a pin number. Did something change with twitter?

Comment by doublere...@gmail.com, May 8, 2011

@jgreg yes it seems that the PIN is now in a code element, https://github.com/stereoket/oauth-adapter has the change, he just parses the document HTML with a regex.

I've made my own version of this which works on Android, I hope to have the time to post it soon.

Comment by rafaelfa...@gmail.com, May 12, 2011

Everytime i try twitter using the following code:

Ti.include('./lib/oauth_adapter.js');

var oAuthAdapter = new OAuthAdapter(
'YOU KNOW', 'YOU KNOW', 'HMAC-SHA1'
);

// load the access token for the service (if previously saved) oAuthAdapter.loadAccessToken('twitter');

// consume a service API - in this case the status update by Twitter. notice the nested array for the parameters argument oAuthAdapter.send('https://api.twitter.com/1/statuses/update.json', [['status','Hey @ziodave, I managed to use the #oauth adapter for @titanium consuming @twitterapi']],'Twitter','Tweet published.','Tweet not published.');
// if the client is not authorized, ask for authorization. the previous tweet will be sent automatically after authorization if (oAuthAdapter.isAuthorized() == false) {
// this function will be called as soon as the application is authorized
var receivePin = function() {
// get the access token with the provided pin/oauth_verifier
oAuthAdapter.getAccessToken('https://api.twitter.com/oauth/access_token');
// save the access token
oAuthAdapter.saveAccessToken('twitter');
};
// show the authorization UI and call back the receive PIN function
oAuthAdapter.showAuthorizeUI('https://api.twitter.com/oauth/authorize?' + oAuthAdapter.getRequestToken('https://api.twitter.com/oauth/request_token'), receivePin);
}

I get the following error:

INFO? INFO? If you like the OAuth Adapter, consider donating at INFO? https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=T5HUU4J5EQTJU&lc=IT&item_name=OAuth%20Adapter&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted INFO? Entity: line 18: parser error : Opening and ending tag mismatch: link line 7 and head </head><body class="tfw en logged-out oauth write "> ^ Entity: line 44: parser error : Opening and ending tag mismatch: img line 42 and h3 </h3> ^ Entity: line 51: parser error : Opening and ending tag mismatch: h3 line 41 and div </div> ^ Entity: line 71: parser error : Opening and ending tag mismatch: input line 71 and div city_token" type="hidden" value="YOU KNOW"></div ^ Entity: line 80: parser error : Opening and ending tag mismatch: input line 79 and span </span> ^ Entity: line 81: parser error : Opening and ending tag mismatch: span line 78 and div </div> ^ Entity: line 87: parser error : Opening and ending tag mismatch: input line 86 and span </span> ^ Entity: line 88: parser error : Opening and ending tag mismatch: span line 85 and div </div> ^ Entity: line 89: parser error : Opening and ending tag mismatch: div line 83 and fieldset </fieldset> ^ Entity: line 99: parser error : Opening and ending tag mismatch: input line 98 and fieldset </fieldset> ^ Entity: line 100: parser error : Opening and ending tag mismatch: input line 97 and form </form> ^ Entity: line 111: parser error : Opening and ending tag mismatch: fieldset line 95 and div </div> ^ Entity: line 160: parser error : xmlParseEntityRef: no name window.pageTracker && window.pageTracker.trackPageview('/oauth/approved/Can ^ Entity: line 160: parser error : xmlParseEntityRef: no name window.pageTracker && window.pageTracker.trackPageview('/oauth/approved/Can ^ Entity: line 164: parser error : xmlParseEntityRef: no name window.pageTracker && window.pageTracker.trackPageview('/oauth/declined/Can ^ Entity: line 164: parser error : xmlParseEntityRef: no name window.pageTracker && window.pageTracker.trackPageview('/oauth/declined/Can ^ Entity: line 173: parser error : StartTag?: invalid element name if(window.innerHeight < $('#bd').height()+160) { ^ Entity: line 209: parser error : Opening and ending tag mismatch: fieldset line 74 and body </body></html> ^ Entity: line 209: parser error : Opening and ending tag mismatch: input line 73 and html </body></html> ^ Entity: line 209: parser error : Premature end of data in tag div line 71 </body></html> ^ Entity: line 209: parser error : Premature end of data in tag form line 71 </body></html> ^ Entity: line 209: parser error : Premature end of data in tag div line 40 </body></html> ^ Entity: line 209: parser error : Premature end of data in tag div line 36 </body></html> ^ Entity: line 209: parser error : Premature end of data in tag div line 29 </body></html> ^ Entity: line 209: parser error : Premature end of data in tag body line 18 </body></html> ^ Entity: line 209: parser error : Premature end of data in tag link line 6 </body></html> ^ Entity: line 209: parser error : Premature end of data in tag meta line 4 </body></html> ^ Entity: line 209: parser error : Premature end of data in tag meta line 3 </body></html> ^ Entity: line 209: parser error : Premature end of data in tag head line 1 </body></html> ^ Entity: line 209: parser error : Premature end of data in tag html line 1 </body></html> ^ ERROR? Error Domain=com.google.GDataXML Code=-1 "The operation couldn’t be completed. (com.google.GDataXML error -1.)". in -parseString:? (TiDOMDocumentProxy.m:50) ERROR? The application has crashed with an unhandled exception. Stack trace:

Any ideas?

Comment by rafaelfa...@gmail.com, May 12, 2011

Apparently i get the error above when i reach to this line

var xmlDocument = Ti.XML.parseString(e.source.html);

Does it means the twitter html is not valid? What should I do?

Thanks

Comment by jkriti...@gmail.com, May 16, 2011

Seems like the process has changed on Twitter's end, but no update on the documentation..

Comment by anirudh1...@gmail.com, May 18, 2011

Even, im getting parser error!! any fix for this?

Comment by calibana...@gmail.com, May 30, 2011

Hi, a very ugly workaround, but it worked for me.

In oauth_adapter.js remove authorizeUICallback (should be at line 226) with the following lines:

var authorizeUICallback = function(e) {
Ti.API.debug('authorizeUILoaded'); Ti.API.debug('Url:'+ e.url );

if( e.url.indexOf( 'https://api.twitter.com/oauth/authorize?' ) == -1 )
{ Ti.API.debug('HTML:' + e.source.html);
var positionStart = e.source.html.indexOf( '<code>' ) + 6; var positionEnd = e.source.html.indexOf( '</code>' ); if( positionStart && positionEnd ) { pin = e.source.html.substring( positionStart, positionEnd ); Ti.API.debug( pin ); if (receivePinCallback) setTimeout(receivePinCallback, 100); destroyAuthorizeUI(); } nodeList = null; xmlDocument = null; } };

Comment by cwhi...@gmail.com, Jun 22, 2011

I had an issue where I've got a hybrid app (browser and client) so to make it work I had to set my twitter profile to Browser but that was breaking the app (not really breaking just not working) .. So I edited the authorizeUICallback... Here is my change just in case someone else runs into this problem... `// looks for the PIN everytime the user clicks on the WebView? to authorize the APP

// currently works with TWITTER var authorizeUICallback = function(e) {
Ti.API.debug('authorizeUILoaded'); var url = e.url; //alert(url); var val = null; if(url.indexOf("oauth_verifier") > -1) {
var params = getUrlVars(url); val = params["oauth_verifier"];
} else {
val = webView.evalJS('window.document.querySelector(\'kbd[aria-labelledby="code-desc"] > code\').innerHTML');
} if( val ) {
pin = val; if (receivePinCallback)
receivePinCallback();
}

}; function getUrlVars(url) {
var vars = {}; var parts = url.replace(/[?&]+([=&]+)=([&])/gi, function(m,key,value) {
varskey? = value;
}); return vars;
}`
Comment by ArnCi...@gmail.com, Jul 10, 2011

And how to do work with Google i mean Docs, Gmail, Mail and so on. I have only my Email and password, so how to authenticate thru my google account. There are similar tutorial http://mobile.tutsplus.com/tutorials/appcelerator/titanium-user-authentication/ like i say just with google account. Thanks for advance. P.S. sorry for my poor English xD

Comment by cyblob, Jul 15, 2011

Fixes to the fix on 30th May that handle bad authorisation attempts:

    var authorizeUICallback = function(e) {
        Ti.API.debug('authorizeUILoaded');
        Ti.API.debug('Url:'+ e.url );
        if( e.url.indexOf( 'https://api.twitter.com/oauth/authorize?' ) == -1 ) {
            //Ti.API.debug('HTML:' + e.source.html);
            var positionStart = e.source.html.indexOf( '<code>' );
            var positionEnd = e.source.html.indexOf( '</code>' );
            if( positionStart != -1 && positionEnd != -1) {
                pin = e.source.html.substring( positionStart + 6, positionEnd );
                Ti.API.debug( "pin: " + pin );
                if (receivePinCallback)
                    setTimeout(receivePinCallback, 100);
                
                destroyAuthorizeUI();
                
            }
            nodeList = null;
            xmlDocument = null;
        }
    };

Also had to change line 197 from window.hide() to window.close();

Works great now.

Comment by yannick....@gmail.com, Jul 18, 2011

Works fine now !

Real thank cyblob u're the "TitatwitGod?".

Comment by Michael....@gmail.com, Feb 9, 2012

Anyone getting this error from Twitter when the auth UI window appears?

"Whoa there! The request token for this page is invalid. It may have already been used, or expired because it is too old. Please go back to the site or application that sent you here and try again; it was probably just a mistake"

Comment by dariomar...@gmail.com, Feb 11, 2012

Thanks cyblob!

Comment by dariomar...@gmail.com, Feb 13, 2012

I've made the changes illustrated by cyblob and it's working on iOS but when I've tried this on Android I got:

Whoa there! There is no request token for this page. That's the special key we need from applications asking to use your Twitter account. Please go back to the site or application that sent you here and try again; it was probably just a mistake.

Anyone else getting this error?

Comment by rcke...@gmail.com, Feb 29, 2012

If anyone is getting trouble with the pin, and an XML parsing error... Replace the function with this one... I had to re-make it using regular expressions...

var authorizeUICallback = function(e)

{
Ti.API.debug('authorizeUILoaded');
// document.getElementsByTagName("code");
var htmlDocument = e.source.html;
var pattern = /<code>([0-9]+)<\/code>/; var tagSearch = htmlDocument.match(pattern); pin = tagSearch[1]; if (receivePinCallback) setTimeout(receivePinCallback, 100);

id = null; node = null;

destroyAuthorizeUI();

};


Sign in to add a comment
Powered by Google Project Hosting