Reputation: 107
I have a piece of code that do not work, and I cannot understand why. As the subject says, it logs in to Twitter, but redirects back to the sign in button. setupTimeline(); is never executed.
I am using twitter4j library, it is at the latest version, 4.0.7.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the preferences for the app.
tweetzPrefs = getSharedPreferences("TweetzPrefs", 0);
// Find out if the user preferences are set.
if (tweetzPrefs.getString("user_token", null) == null) {
// No user preferences so prompt to sign in.
setContentView(R.layout.activity_main);
// Get a twitter instance for authentication.
tweetzTwitter = new TwitterFactory().getInstance();
// Pass developer key and secret.
tweetzTwitter.setOAuthConsumer(TWIT_KEY, TWIT_SECRET);
// Try to get request token.
try {
new Thread(new Runnable() {
@Override
public void run() {
try {
// Get authentication request token.
tweetzRequestToken = tweetzTwitter.getOAuthRequestToken(TWIT_URL);
Log.e(LOG_TAG, "Are we there Yeti?");
} catch (TwitterException e) {
e.printStackTrace();
Log.e(LOG_TAG, "TwitterException: " + e.getMessage());
}
if (tweetzRequestToken == null) {
Log.e(LOG_TAG, "tweetzRequestToken == null.");
}
}
}).start();
// Get authentication request token.
// tweetzRequestToken = tweetzTwitter.getOAuthRequestToken(TWIT_URL);
} catch (Exception e) {
e.printStackTrace();
Log.e(LOG_TAG, "Exception: " + e.getMessage());
}
// Setup button for click listener.
Button signIn = (Button) findViewById(R.id.signin);
signIn.setOnClickListener(this);
} else {
// User preferences are set, get timeline.
setupTimeline();
}
}
Any ideas anyone?
Regards.
Upvotes: 1
Views: 64