Android アプリケーションに Twitter4J を実装しましたが、問題なく動作します。しかし、Twitterのログインページでログインした後、ユーザーに手動でPINコードを入力するように求めます.
Twitter4J クラスには、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番号を入力せずに認証する方法は? 私は何か間違ったことをしていますか?
私を助けてください。
ありがとうございました