我相信我已经正确编码并设置了对Twitter的Signpost调用。在API 10(通过仿真器和实际手机)上运行时,它完全正常工作。但是当我在API 15或16上尝试完全相同的apk时,回调根本不起作用。它不是将我返回到我的应用程序,而是将其发送到另一个页面,该页面显示该页面不可用并标识我的回调URL + oauth令牌。我有
重写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);
}
我的auth电话看起来像这样:
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);
}
我的logcat看起来还不错,虽然我对“没有检测到GPU仿真的仿真器”有点怀疑,因为我在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