3

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

Community
  • 1
  • 1
mendorphis
  • 63
  • 6

1 Answers1

0

I also stumbled upon this problem. The solution is simple: Just add callback url to the twitter appenter image description here

Gaurav Vashisth
  • 7,547
  • 8
  • 35
  • 56
  • Actually I already added a callback url and I'm controlling it. I've tried various ways to get rid of it including changin callback url. – mendorphis Apr 24 '13 at 14:42