在Twitter4j中使用OAuth玩了一段时间。在此之前,我遇到了#3255153中详细描述的问题和401错误,但终于修复了这些问题,并且遇到了难以解决的问题。Twitter4j OAuth回调成功,但测试鸣叫失败
Twitter应用程序授权页面在浏览器中启动,我登录并批准我的帐户的应用程序。然后它重定向回应用程序,并且没有任何反应。该视图与启动授权页面之前完全相同。
要查看它是否有效,我将它设置为Toast消息,说明“登录到Twitter成功”,在onResume或onNewIntent(如下所示)中,它永远不会弹出。成功的回调URL被接收,但是,由于该项在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
这里是我的onNewIntent(也有的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);
}
}
}
和相关位我清单:
<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>
我有同样的问题。你是否设法为你的问题找到解决方案? – Dilberted 2012-04-30 07:30:33