我相信我已经正确编码并设置了对 Twitter 的 Signpost 调用。在 API 10 上运行时(通过模拟器和实际手机),一切都运行良好。但是当我在 API 15 或 16 上尝试完全相同的 apk 时,回调根本不起作用。它没有将我返回到我的应用程序,而是将我发送到另一个网页,该网页显示该页面不可用并标识了我的回调 URL + oauth 令牌。我有
- 为活动设置 android:launchMode="singleInstance"
- 设置 android:scheme 和 android:host 以匹配传递给 retrieveRequestToken 的回调 URL
覆盖 onNewIntent
<activity android:name=".TimelineActivity" android:label="@string/app_name" android:launchMode="singleInstance"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <!-- Used for OAuth callback --> <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="x-AbcdEfg41-oauth-twitter" android:host="callback" /> </intent-filter> </activity>
onNewIntent 看起来像这样:
super.onNewIntent(intent);
Log.d(TAG, "intent: " + intent);
//check if this is a callback from OAuth
Uri uri = intent.getData();
if (uri != null && uri.getScheme().equals(OAUTH_CALLBACK_SCHEME)) {
Log.d(TAG, "callback: " + uri.getPath());
String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);
Log.d(TAG, "verifier: " + verifier);
new RetrieveAccessTokenTask().execute(verifier);
}
我的身份验证调用如下所示:
try {
authUrl = this.mProvider.retrieveRequestToken(this.mConsumer, OAUTH_CALLBACK_URL);
Log.d(TAG, authUrl);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
虽然我对“没有检测到 GPU 仿真的模拟器”有点怀疑,但我的 logcat 看起来还不错,只是因为我在 API 10 上运行时没有看到:
12-07 04:48:31.428: I/TimelineApplication(754): onCreate
12-07 04:48:31.598: I/TimelineActivity(754): onCreate(). Starting authorizaion.
12-07 04:48:31.658: I/dalvikvm(754): threadid=3: reacting to signal 3
12-07 04:48:31.678: I/dalvikvm(754): Wrote stack traces to '/data/anr/traces.txt'
12-07 04:48:31.758: D/TimelineActivity(754): OAuthAuthorizeTask.doInBackground()
12-07 04:48:31.857: D/gralloc_goldfish(754): Emulator without GPU emulation detected.
12-07 04:48:32.968: D/dalvikvm(754): GC_CONCURRENT freed 206K, 3% free 12797K/13063K, paused 7ms+6ms
12-07 04:48:33.907: D/TimelineApplication(754): https://api.twitter.com/oauth/authorize?oauth_token=QepbZdXy2uiDFt7vrwvwq72Wl1S2IzsZywCPHwx8jTk
12-07 04:48:33.968: D/TimelineApplication(754): oAuthAuthorize() has finished
12-07 04:48:34.139: D/TimelineActivity(754): OAuthAuthorizeTask.onPostExecute()
12-07 04:48:34.368: D/TimelineActivity(754): the result is NULL