Having a rough time with OAuth in Twitter4j. Before this, I had the problem detailed in #3255153 and a 401 error, but finally fixed those, and ran into a harder to solve problem.
The Twitter application authorization page launches in a browser, I log in, and approve the application for my account. It then redirects back to the application, and nothing happens. The view is the exact same as before launching the authorization page.
To see if it had worked, I have it set to Toast a message saying "Login to Twitter Successful", in either onResume or onNewIntent (shown below), which never pops. The successful callback URL is received, however, as this entry shows up in LogCat:
12-18 09:25:50.426: I/ActivityManager(186): Starting: Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=snapp://twitter?oauth_token=tokenhere&oauth_verifier=verifierhere cmp=com.infini_servers.snapp/.SnappActivity } from pid 7853
Here's my onNewIntent (also have a virtual clone for onResume):
@Override
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
Uri uri = intent.getData();
if (uri != null && uri.toString().startsWith(CALLBACKURL))
{
Toast.makeText(getBaseContext(), "Login to twitter successful!", Toast.LENGTH_LONG);
String verifier = uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_VERIFIER);
try
{
provider.retrieveAccessToken(consumer, verifier);
AccessToken accessToken = new AccessToken(consumer.getToken(),
consumer.getTokenSecret());
twitter.setOAuthConsumer(consumerKey, consumerSecret);
twitter.setOAuthAccessToken(accessToken);
String tweet = "Test";
twitter.updateStatus(tweet);
Toast.makeText(getBaseContext(), "Tweet Successful!", Toast.LENGTH_LONG);
}
catch (Exception e)
{
Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG);
}
}
}
And the relevant bits of my Manifest:
<activity
android:label="@string/app_name"
android:name=".SnappLaunch" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="@string/app_name"
android:name=".SnappActivity"
android:launchMode="singleInstance" >
<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="snapp" android:host="twitter" />
</intent-filter>
</activity>