I'm using Twitter4j library to authorize user with OAuth for my application on Android. But I'm facing this exception when I try to get OAuth request token. I know there are bunch of topics about this (Twitter4J + Android: Authentication Challenge is Null Exception like this one) but none did fix my problem. Here is the simple code sample that explains my problem;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
prefs = getSharedPreferences("twitterPrefs", MODE_PRIVATE);
twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
LoginButton = (Button) findViewById(R.id.login_button);
}
I'm setting consumer key and also secret key, and I get well formed twitter object but when user clicks on the login button;
private void loginNewUser() {
try {
currentRequestToken = twitter.getOAuthRequestToken(CALLBACK_URL);
setUpViews();
WebView twitterSite = new WebView(this);
twitterSite.loadUrl(currentRequestToken.getAuthenticationURL());
setContentView(R.layout.authorization_view);
} catch (TwitterException e) {
Toast.makeText(this, "Twitter Login error, try again later", Toast.LENGTH_SHORT).show();
}
}
I get exception because getOAuthRequestToken(CALLBACK_URL) equals null; received authentication challenge is null.
I'm sure that timestamp is true on device and also async task for request token didn't work.
Any help would be appreciated