【发布时间】:2019-07-01 14:33:57
【问题描述】:
我已经在我的 Android 应用程序中实现了 Twitter4J,它运行良好。 但是当我使用 twitter 登录页面登录后,它要求用户手动输入 PIN 码。
在 Twitter4J 类中,有一种方法可以检索和存储(到 sharedpreferences 中)OAuth 和 oauth_token_secret。
/**
* Retrieve the oauth_verifier, and store the oauth and oauth_token_secret
* for future API calls.
*/
@Override
protected Void doInBackground(Uri...params) {
final Uri uri = params[0];
final String oauth_verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);
try {
provider.retrieveAccessToken(consumer, oauth_verifier);
final Editor edit = prefs.edit();
edit.putString(OAuth.OAUTH_TOKEN, consumer.getToken());
edit.putString(OAuth.OAUTH_TOKEN_SECRET, consumer.getTokenSecret());
edit.commit();
String token = prefs.getString(OAuth.OAUTH_TOKEN, "");
String secret = prefs.getString(OAuth.OAUTH_TOKEN_SECRET, "");
consumer.setTokenWithSecret(token, secret);
context.startActivity(new Intent(context,MainAct.class));
executeAfterAccessTokenRetrieval();
Log.i(TAG, "OAuth - Access Token Retrieved");
} catch (Exception e) {
Log.e(TAG, "OAuth - Access Token Retrieval Error", e);
}
return null;
}
清单 - PrepareRequestTokenActivity
<activity android:name=".PrepareRequestTokenActivity" android:launchMode="singleTask">>
<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-oauthflow-twitter" android:host="callback" />
</intent-filter>
</activity>
我不明白为什么它不检索OAUTH_TOKEN 和OAUTH_SECRET。
如何在不输入 PIN 码的情况下进行授权?我做错了吗?
请帮帮我。
谢谢
【问题讨论】:
-
你用过哪些类?并向你展示一些清单文件和常量类的代码
-
我使用github.com/ddewaele/AndroidTwitterSample 进行 twitter4j 集成。我已经编辑了问题,请看一下。