Select Page
Error message during callback:
“02-22 19:26:16.415: ERROR/Tab(417): onReceivedError -10 myapp://oauthactivity?oauth_token=&oauth_verifier= The protocol is not supported.”
Will get straight to the point.  I wanted to integrate Twitter sign-in with my Android App and I ran into the above error message.  The browser would redirect to an invalid page and not to my actual app.  I made ‘some’ modifications and the integration somehow works now.  I’m not sure exactly why it works now and not before BUT I did suspect the following:
1. String authUrl = provider.retrieveRequestToken(consumer, Uri.parse(CALLBACK_URL).toString()); : I was able to verify that this did NOT fix anything
2. ordering of Manifest Intent filters : I did try playing around with the ordering but it doesn’t seem to change anything
Eh, sometimes as a developer you just need to accept oddities like this and continue flowing down the pipeline of feature requests…
Libraries used:
  1. Twitter4J: twitter4j-core-android-2.2.0-SNAPSHOT.jar
  2. signpost-core: signpost-core-1.2.1.1.jar
  3. signpost-commonshttp: signpost-commonshttp4-1.2.1.1.jar
Setup:
+ I created a Twitter app using dev.twitter.com and chose ‘Browser’ NOT ‘client’
Code:
+ Declare Variables
{
//Twitter
private Twitter twitter;
//private OAuthProvider provider;
private CommonsHttpOAuthProvider provider;
private CommonsHttpOAuthConsumer consumer;
private String CONSUMER_KEY = “XOXO”;
private String CONSUMER_SECRET = “XOXO”;
//CALLBACK FORMAT: HOST://PATH
private String CALLBACK_URL = “myapptest://testing”;
}
+ onClick event for Twitter login
/**
* Open the browser and asks the user to authorize the app.
* Afterwards, we redirect the user back here!
*/
private void askOAuth() {
try {
consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEYCONSUMER_SECRET);
provider = new CommonsHttpOAuthProvider( “https://api.twitter.com/oauth/request_token”,
“https://api.twitter.com/oauth/access_token”“https://api.twitter.com/oauth/authorize”);

//WHEN I USE JUST CALLBACK_URL, I GET THE PROTOCOL NOT SUPPORT ERROR
//FOR SOME ODD REASON, WHEN I USE Uri.parse(CALLBACK_URL).toString(), THEN IT WORKS
String authUrl = provider.retrieveRequestToken(consumer, Uri.parse(CALLBACK_URL).toString());
Toast.makeText(this“Please authorize this app!”, Toast.LENGTH_LONG).show();
Log.d(“OAuth”“url is “ + authUrl);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
catch (Exception e) {
Log.e(APP, e.getMessage());
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
+ onResume and onNewIntent(Intent intent) custom implementation that gets called via twitter callback

+ Manifest snippet
<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=“oauthactivity”/>
intent-filter>