OAuth + Twitter on Android: callback not working

My Android application uses the Java OAuth library, found here for authorization on Twitter. I can get the request token, allow the token and get confirmation, but when the browser tries to return the re-connect URL to my application, it does not use the URL that I provide in the code, but uses the one that I provided when registering with Twitter .

Note:
1. When registering my twitter application, I provided a hypothetical return URL: http://abz.xyc.com and set the type of application as a browser.
2. I provided the callback URL in my "myapp" code and added an intent filter for my activity using the "View" and "Data Schema" categories as "myapp".
3. The URL that is called during authorization contains the callback URL that I specified in the code.

Any idea what I'm doing wrong here?

Relevant Code:

public class FirstActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); OAuthAccessor client = defaultClient(); Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(client.consumer.serviceProvider.userAuthorizationURL + "?oauth_token=" + client.requestToken + "&oauth_callback=" + client.consumer.callbackURL)); startActivity(i); } OAuthServiceProvider defaultProvider() { return new OAuthServiceProvider(GeneralRuntimeConstants.request_token_URL, GeneralRuntimeConstants.authorize_url, GeneralRuntimeConstants.access_token_url); } OAuthAccessor defaultClient() { String callbackUrl = "myapp:///"; OAuthServiceProvider provider = defaultProvider(); OAuthConsumer consumer = new OAuthConsumer(callbackUrl, GeneralRuntimeConstants.consumer_key, GeneralRuntimeConstants.consumer_secret, provider); OAuthAccessor accessor = new OAuthAccessor(consumer); OAuthClient client = new OAuthClient(new HttpClient4()); try { client.getRequestToken(accessor); } catch (Exception e) { e.printStackTrace(); } return accessor; } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); Uri uri = this.getIntent().getData(); if (uri != null) { String access_token = uri.getQueryParameter("oauth_token"); } } } // Manifest file <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".FirstActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="myapp"/> </intent-filter> </activity> </application> 
+7
android oauth twitter twitter client
source share
4 answers

Twitter does not honor callbacks requested in OAuth requests ( Twitter API Announce ) and will only be redirected to the callback URL specified in the application settings (note that "localhost" is not allowed).

I assume you have noted the Oauth-callback-on-android question.

Android guesswork -
After a little reading, I see that the Android browser redirects MyApp: /// to your application, and I assume that Twitter will not like this custom URI prefix. I'm not an Android developer, but one suggestion I can make is to get "www.myapp.com" on the Internet and redirect there.

So, your OAuth goes back to http://www.myapp.com/redirect.aspx?oauth_token=abc and redirects this page to myapp:///oauth_token=... (desired result)

+11
source share

In my case, it works for me:

  String authURL = m_provider.retrieveRequestToken (m_consumer, CALLBACK_URL); 

And in the manifest:

  <activity android:configChanges = "keyboardHidden|orientation" android:name = "xxxx.android.xxxxx"> <intent-filter> <action android:name = "android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="myapp" android:host="tweet" /> </intent-filter> 

In this case, the callback url will be: myapp: // tweet

+3
source share

It seems to me that you are doing the right thing, and Twitter is fascinating, always accepting your registered callback URL. Is there a way to change the registered URL? Perhaps you can re-register and try the Android callback next time, see what happens.

0
source share

My problem was that I was trying to log in with the same account that I did on the Twitter application. After I logged into my personal profile, the callback works (for now).

0
source share

All Articles