Search in sources :

Example 1 with OAuth2Token

use of twitter4j.auth.OAuth2Token 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 2 with OAuth2Token

use of twitter4j.auth.OAuth2Token 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)

Aggregations

OAuth2Token (twitter4j.auth.OAuth2Token)2 ConfigurationBuilder (twitter4j.conf.ConfigurationBuilder)2 Map (java.util.Map)1