Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android - Tweet function keeps asking for authorizing the app. #9

Open
johnrgoslin opened this issue Jun 1, 2011 · 13 comments
Open

Comments

@johnrgoslin
Copy link

Using the Birdhouse.js version .9 on android keeps requesting authorization even after the app has been authorized. The code works without issue on iPhone.

Here is my code:

var tweet_it = function(){
bh.authorize();
var tweet;
if (Title.length < 30) {tweet = Description} else {tweet = Title};
tweet = "Message content " + shorturl +" "+ tweet;
tweet = tweet.substr(0,140);
bh.tweet(tweet, function(e) {
var alertMsg = Ti.UI.createAlertDialog();
if (e===true) {
alertMsg.message = 'Sent!';
} else {
alertMsg.message = 'Failed!';
}
alertMsg.show();
});
};
bh.shorten_url(Link,tweet_it);

@jpurcell
Copy link
Owner

jpurcell commented Jun 1, 2011

Instead of making a separate function, see if this will accomplish what you're looking to do:

var short_url = bh.shorten_url(Link);
var tweet = "Message content " + shorturl +" "+ tweet;
bh.send_tweet(tweet,function(e){
  if (e===true) {
    alertMsg.message = 'Sent!';
  } else {
    alertMsg.message = 'Failed!';
  }
  alertMsg.show();
});

BirdHouse will automatically require authentication when trying to send a tweet, hence the lack of need to use the bh.authorize. Also, the tweet function opens up a dialog box, so I substituted in the send_tweet function. It should also prevent sending a tweet if it is longer than 140 characters. I hope this works, let us know what you find out!

@johnrgoslin
Copy link
Author

I had it without the authorize before but that didnt help also I want
the dialog box to be there so the user can edit the tweet if they dont
want the default.


jpurcell
mailto:[email protected]
June 1, 2011 1:41 PM

Instead of making a separate function, see if this will accomplish
what you're looking to do:

var short_url = bh.shorten_url(Link);
var tweet = "Message content " + shorturl +" "+ tweet;
bh.send_tweet(tweet,function(e){
if (e===true) {
alertMsg.message = 'Sent!';
} else {
alertMsg.message = 'Failed!';
}
alertMsg.show();
});

BirdHouse will automatically require authentication when trying to
send a tweet, hence the lack of need to use the bh.authorize. Also,
the tweet function opens up a dialog box, so I substituted in the
send_tweet function. It should also prevent sending a tweet if it is
longer than 140 characters. I hope this works, let us know what you
find out!

@johnrgoslin
Copy link
Author

Sorry, I didn't mention that I never get passed the authorize screen. On the iPhone i get the tweet dialog on android it keeps wanting to authorize even though it already has authorized.

@johnrgoslin
Copy link
Author

Here is some log information:

W/DefaultRequestDirector( 220): Authentication error: Unable to respond to any of these challenges: {oauth=WWW-Authenticate: OAuth realm="https://api.twitter.com"}
D/TiHttpClient( 220): (TiHttpClient-7) [542,223393] Setting ready state to 2
D/TiHttpClient( 220): (TiHttpClient-7) [1,223394] Setting ready state to 3
D/TiHttpClient( 220): (TiHttpClient-7) [24,223418] clearing the expired and idle connections
W/IdleConnectionHandler( 220): Removing a connection that never existed!
W/IdleConnectionHandler( 220): Removing a connection that never existed!
E/TiHttpClient( 220): (TiHttpClient-7) [12,223430] HTTP Error (org.apache.http.client.HttpResponseException): Unauthorized
E/TiHttpClient( 220): org.apache.http.client.HttpResponseException: Unauthorized
E/TiHttpClient( 220): at ti.modules.titanium.network.TiHTTPClient$LocalResponseHandler.handleResponse(TiHTTPClient.java:210)
E/TiHttpClient( 220): at ti.modules.titanium.network.TiHTTPClient$LocalResponseHandler.handleResponse(TiHTTPClient.java:170)
E/TiHttpClient( 220): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:657)
E/TiHttpClient( 220): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:637)
E/TiHttpClient( 220): at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1012)
E/TiHttpClient( 220): at java.lang.Thread.run(Thread.java:1096)
I/TiHttpClient( 220): (TiHttpClient-7) [10,223440] Sending error Unauthorized
W/MessageQueue( 220): Handler{4504efc0} sending message to a Handler on a dead thread
W/MessageQueue( 220): java.lang.RuntimeException: Handler{4504efc0} sending message to a Handler on a dead thread
W/MessageQueue( 220): at android.os.MessageQueue.enqueueMessage(MessageQueue.java:181)
W/MessageQueue( 220): at android.os.Handler.sendMessageAtTime(Handler.java:457)
W/MessageQueue( 220): at android.os.Handler.sendMessageDelayed(Handler.java:430)
W/MessageQueue( 220): at android.os.Handler.post(Handler.java:248)
W/MessageQueue( 220): at org.appcelerator.titanium.kroll.KrollCallback.callAsync(KrollCallback.java:162)
W/MessageQueue( 220): at org.appcelerator.titanium.kroll.KrollCallback.callAsync(KrollCallback.java:96)
W/MessageQueue( 220): at org.appcelerator.titanium.kroll.KrollCallback.callAsync(KrollCallback.java:91)
W/MessageQueue( 220): at ti.modules.titanium.network.TiHTTPClient.fireCallback(TiHTTPClient.java:490)
W/MessageQueue( 220): at ti.modules.titanium.network.TiHTTPClient.sendError(TiHTTPClient.java:522)
W/MessageQueue( 220): at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1032)
W/MessageQueue( 220): at java.lang.Thread.run(Thread.java:1096)
[INFO] Android Emulator has exited

@johnrgoslin
Copy link
Author

I found the issue it has to do with the window being modal and the httpclient. This is a known issue with titanium mobile sdk. Here is my work arround:

function get_request_verifier(callback) {
var url = "http://api.twitter.com/oauth/authorize?oauth_token="+cfg.request_token;
if (Ti.Platform.osname=='iphone') {
var win = Ti.UI.createWindow({
top: 0,
modal: true, // Fix from Appcellerator
fullscreen: true
});
} else {
var win = Ti.UI.createWindow({
top: 0
});
};

This check's to see if the user is using iOS and if not then it removes the fullscreen and modal attributes.

@jpurcell
Copy link
Owner

jpurcell commented Jun 2, 2011

@jgoslin--WOW. That's amazing you figured that out. I was at complete loss as to what the issue was. I will be sure to include this in v1.0, and you get all the credit for that.

Hopefully, others can confirm this is true. On behalf of everyone, thank you!

@jpurcell jpurcell reopened this Jun 2, 2011
@lunika
Copy link

lunika commented Jun 3, 2011

Hello,

thx but this not fix the issue for me.

@mathieugerard
Copy link

This solution (removing the fullscreen and modal attributes) does solve my issue.
Thanks jgoslin!

@pardeike
Copy link

@jgoslin & @jpurcell -- making the dialog non-modal on android fixes the problem for me too.

Here's the change I made to get_request_verifier(callback):

function get_request_verifier(callback) {
  var url = "http://api.twitter.com/oauth/authorize?oauth_token="+cfg.request_token;

  // fix added according to https://github.com/jpurcell/birdhouse/issues/9
  //
  // var win = Ti.UI.createWindow({
  // top: 0,
  // modal: true,
  // fullscreen: true
  //});
  //
  if (Ti.Platform.osname=='iphone') {
   var win = Ti.UI.createWindow({
    top: 0,
    modal: true, // Fix from Appcellerator
    fullscreen: true
   });
  } else {
   var win = Ti.UI.createWindow({
    top: 0
   });
  }
  // end fix

  // add close button on iPhone
  ...

@jpurcell
Copy link
Owner

Hey, thanks pardeike! So, this fixes at least one issue. Currently I haven't had a chance to produce an upgrade, but plan to do so soon and will include your fix. Thanks for posting!

@pardeike
Copy link

And for the sake of completeness: I am using Titanium Studio GM release with Titanium mobile 1.7.0 and compile for iOS 4.3 and for Android API 2.1. Works fine for me.

On a side note, I have a fake completion url which works but on slower devices, it actually shows that page which is ugly and confusing. I will try to find a way to patch this and let you know. Good job so far!!

@enhorn
Copy link

enhorn commented Jul 13, 2011

Thanks. This worked.

Important: It's not enough to set modal & fullscreen to false on Android, they have to be undefined.

@raju-aleti
Copy link

Hi,
I am having similar problem,

I am calling the authorize() function of birdhouse and then it is opening webview to access the twitter , after I give the credentials it's generating the token then its closing that page and giving "failed to authorize" alert.

I am using Titanium sdk 2.1.1 and i have tried android device and emulator(2.3.3 Google API) also.

Please help me.

Thanks
Raj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants