Search in sources :

Example 26 with ConfigurationBuilder

use of twitter4j.conf.ConfigurationBuilder 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)

Example 27 with ConfigurationBuilder

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

the class AsyncTwitterTest method testAppOnlyAuthWithBuildingConf2.

public void testAppOnlyAuthWithBuildingConf2() throws Exception {
    // setup
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setApplicationOnlyAuthEnabled(true);
    builder.setOAuthConsumerKey(browserConsumerKey).setOAuthConsumerSecret(browserConsumerSecret);
    final AsyncTwitter twitter = new AsyncTwitterFactory(builder.build()).getInstance();
    // exercise & verify
    OAuth2Token token = twitter.getOAuth2Token();
    assertEquals("bearer", token.getTokenType());
    TwitterListener listener = new TwitterAdapter() {

        @Override
        public void gotRateLimitStatus(Map<String, RateLimitStatus> rateLimitStatus) {
            super.gotRateLimitStatus(rateLimitStatus);
            RateLimitStatus searchTweetsRateLimit = rateLimitStatus.get("/search/tweets");
            assertNotNull(searchTweetsRateLimit);
            assertEquals(searchTweetsRateLimit.getLimit(), 450);
            notifyResponse();
        }

        @Override
        public void onException(TwitterException ex, TwitterMethod method) {
            assertEquals(403, ex.getStatusCode());
            assertEquals(220, ex.getErrorCode());
            assertEquals("Your credentials do not allow access to this resource", ex.getErrorMessage());
            notifyResponse();
        }
    };
    twitter.addListener(listener);
    twitter.getRateLimitStatus("search");
    waitForResponse();
}
Also used : ConfigurationBuilder(twitter4j.conf.ConfigurationBuilder) OAuth2Token(twitter4j.auth.OAuth2Token) Map(java.util.Map)

Example 28 with ConfigurationBuilder

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

the class AsyncTwitterTest method testAppOnlyAuthAsyncWithBuildingConf1.

public void testAppOnlyAuthAsyncWithBuildingConf1() throws Exception {
    // setup
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setApplicationOnlyAuthEnabled(true);
    final AsyncTwitter twitter = new AsyncTwitterFactory(builder.build()).getInstance();
    // exercise & verify
    twitter.setOAuthConsumer(browserConsumerKey, browserConsumerSecret);
    twitter.addListener(this);
    twitter.getOAuth2TokenAsync();
    waitForResponse();
    testRateLimitStatus();
}
Also used : ConfigurationBuilder(twitter4j.conf.ConfigurationBuilder)

Example 29 with ConfigurationBuilder

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

the class AsyncTwitterTest method testAppOnlyAuthWithBuildingConf1.

public void testAppOnlyAuthWithBuildingConf1() throws Exception {
    // setup
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setApplicationOnlyAuthEnabled(true);
    final AsyncTwitter twitter = new AsyncTwitterFactory(builder.build()).getInstance();
    // exercise & verify
    twitter.setOAuthConsumer(browserConsumerKey, browserConsumerSecret);
    OAuth2Token token = twitter.getOAuth2Token();
    assertEquals("bearer", token.getTokenType());
    twitter.addListener(this);
    testRateLimitStatus();
}
Also used : ConfigurationBuilder(twitter4j.conf.ConfigurationBuilder) OAuth2Token(twitter4j.auth.OAuth2Token)

Example 30 with ConfigurationBuilder

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

the class AsyncTwitterTest method testAppOnlyAuthAsyncWithBuildingConf2.

public void testAppOnlyAuthAsyncWithBuildingConf2() throws Exception {
    // setup
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setApplicationOnlyAuthEnabled(true);
    builder.setOAuthConsumerKey(browserConsumerKey).setOAuthConsumerSecret(browserConsumerSecret);
    final AsyncTwitter twitter = new AsyncTwitterFactory(builder.build()).getInstance();
    // exercise & verify
    twitter.addListener(this);
    twitter.getOAuth2TokenAsync();
    waitForResponse();
    TwitterListener listener = new TwitterAdapter() {

        @Override
        public void gotRateLimitStatus(Map<String, RateLimitStatus> rateLimitStatus) {
            super.gotRateLimitStatus(rateLimitStatus);
            RateLimitStatus searchTweetsRateLimit = rateLimitStatus.get("/search/tweets");
            assertNotNull(searchTweetsRateLimit);
            assertEquals(searchTweetsRateLimit.getLimit(), 450);
            notifyResponse();
        }

        @Override
        public void onException(TwitterException ex, TwitterMethod method) {
            assertEquals(403, ex.getStatusCode());
            assertEquals(220, ex.getErrorCode());
            assertEquals("Your credentials do not allow access to this resource", ex.getErrorMessage());
            notifyResponse();
        }
    };
    twitter.addListener(listener);
    twitter.getRateLimitStatus("search");
    waitForResponse();
}
Also used : ConfigurationBuilder(twitter4j.conf.ConfigurationBuilder) Map(java.util.Map)

Aggregations

ConfigurationBuilder (twitter4j.conf.ConfigurationBuilder)31 TwitterFactory (twitter4j.TwitterFactory)9 Configuration (twitter4j.conf.Configuration)4 TwitterStreamFactory (twitter4j.TwitterStreamFactory)3 AppSettings (com.klinker.android.twitter.settings.AppSettings)2 Map (java.util.Map)2 OAuth2Token (twitter4j.auth.OAuth2Token)2 OAuthAuthorization (twitter4j.auth.OAuthAuthorization)2 AlarmManager (android.app.AlarmManager)1 AlertDialog (android.app.AlertDialog)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)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