Search in sources :

Example 6 with Configuration

use of twitter4j.conf.Configuration in project twitter4j by yusuke.

the class OAuthTest method testXAuth.

public void testXAuth() throws Exception {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(desktopConsumerKey);
    builder.setOAuthConsumerSecret(desktopConsumerSecret);
    Twitter twitter = new TwitterFactory(builder.build()).getInstance();
    try {
        twitter.getOAuthAccessToken(id1.screenName, id2.password);
        fail("expecting TwitterException");
    } catch (TwitterException te) {
        // id1 doesn't have access to xAuth
        assertEquals(403, te.getStatusCode());
    }
    InputStream is = OAuthTest.class.getResourceAsStream("/xauth-test.properties");
    if (null == is) {
        System.out.println("xauth-test.properties not found. skipping xAuth test.");
    } else {
        Properties props = new Properties();
        props.load(is);
        Configuration conf = new PropertyConfiguration(props);
        twitter = new TwitterFactory(conf).getInstance();
        twitter.getOAuthAccessToken(id1.screenName, id1.password);
        twitter.updateStatus(new Date() + ": xAuth test.");
        twitter = new TwitterFactory().getInstance();
        twitter.setOAuthConsumer(conf.getOAuthConsumerKey(), conf.getOAuthConsumerSecret());
        twitter.getOAuthAccessToken(id1.screenName, id1.password);
    }
}
Also used : ConfigurationBuilder(twitter4j.conf.ConfigurationBuilder) Configuration(twitter4j.conf.Configuration) PropertyConfiguration(twitter4j.conf.PropertyConfiguration) InputStream(java.io.InputStream) PropertyConfiguration(twitter4j.conf.PropertyConfiguration)

Aggregations

Configuration (twitter4j.conf.Configuration)6 ConfigurationBuilder (twitter4j.conf.ConfigurationBuilder)4 TwitterFactory (twitter4j.TwitterFactory)3 Intent (android.content.Intent)2 InputStream (java.io.InputStream)2 Date (java.util.Date)2 TwitterException (twitter4j.TwitterException)2 PropertyConfiguration (twitter4j.conf.PropertyConfiguration)2 AlarmManager (android.app.AlarmManager)1 AlertDialog (android.app.AlertDialog)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 SharedPreferences (android.content.SharedPreferences)1 View (android.view.View)1 Animation (android.view.animation.Animation)1 CookieManager (android.webkit.CookieManager)1 WebView (android.webkit.WebView)1 WebViewClient (android.webkit.WebViewClient)1 TextView (android.widget.TextView)1 ViewSwitcher (android.widget.ViewSwitcher)1