use of twitter4j.conf.ConfigurationBuilder in project twitter4j by yusuke.
the class OAuthTest method testOAuth.
public void testOAuth() throws Exception {
ConfigurationBuilder build = new ConfigurationBuilder();
String oAuthAccessToken = p.getProperty("id1.oauth.accessToken");
String oAuthAccessTokenSecret = p.getProperty("id1.oauth.accessTokenSecret");
String oAuthConsumerKey = p.getProperty("oauth.consumerKey");
String oAuthConsumerSecret = p.getProperty("oauth.consumerSecret");
build.setOAuthAccessToken(oAuthAccessToken);
build.setOAuthAccessTokenSecret(oAuthAccessTokenSecret);
build.setOAuthConsumerKey(oAuthConsumerKey);
build.setOAuthConsumerSecret(oAuthConsumerSecret);
OAuthAuthorization auth = new OAuthAuthorization(build.build());
Twitter twitter = new TwitterFactory().getInstance(auth);
twitter.verifyCredentials();
}
use of twitter4j.conf.ConfigurationBuilder in project twitter4j by yusuke.
the class ApplicationOnlyAuthTest method testSettingAccessToken2.
public void testSettingAccessToken2() throws TwitterException {
// setup
builder.setOAuthConsumerKey(browserConsumerKey).setOAuthConsumerSecret(browserConsumerSecret);
OAuth2Token token = new TwitterFactory(builder.build()).getInstance().getOAuth2Token();
// exercise & verify
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setApplicationOnlyAuthEnabled(true);
cb.setOAuthConsumerKey(browserConsumerKey);
cb.setOAuthConsumerSecret(browserConsumerSecret);
cb.setOAuth2TokenType(token.getTokenType());
cb.setOAuth2AccessToken(token.getAccessToken());
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
Map<String, RateLimitStatus> rateLimitStatus = twitter.getRateLimitStatus("search");
RateLimitStatus searchTweetsRateLimit = rateLimitStatus.get("/search/tweets");
assertNotNull(searchTweetsRateLimit);
assertEquals(searchTweetsRateLimit.getLimit(), 450);
}
use of twitter4j.conf.ConfigurationBuilder in project twitter4j by yusuke.
the class DAOTest method getJSONObjectFromPostURL.
private JSONObject getJSONObjectFromPostURL(String url) throws Exception {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setUser(id1.screenName);
builder.setPassword(id1.password);
return getJSONObjectFromPostURL(url, builder.build());
}
use of twitter4j.conf.ConfigurationBuilder in project opennms by OpenNMS.
the class MicroblogClient method getTwitter.
public Twitter getTwitter(final String profile) {
final MicroblogProfile mp = getProfile(profile);
final ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setClientURL(mp.getServiceUrl());
if (!isEmpty(mp.getOauthConsumerKey()))
builder.setOAuthConsumerKey(mp.getOauthConsumerKey().orElse(null));
if (!isEmpty(mp.getOauthConsumerSecret()))
builder.setOAuthConsumerSecret(mp.getOauthConsumerSecret().orElse(null));
if (!isEmpty(mp.getOauthAccessToken()))
builder.setOAuthAccessToken(mp.getOauthAccessToken().orElse(null));
if (!isEmpty(mp.getOauthAccessTokenSecret()))
builder.setOAuthAccessTokenSecret(mp.getOauthAccessTokenSecret().orElse(null));
if (!isEmpty(mp.getAuthenUsername()))
builder.setUser(mp.getAuthenUsername().orElse(null));
if (!isEmpty(mp.getAuthenPassword()))
builder.setPassword(mp.getAuthenPassword().orElse(null));
return new TwitterFactory(builder.build()).getInstance();
}
use of twitter4j.conf.ConfigurationBuilder in project tdi-studio-se by Talend.
the class TwitterLoad method twitterStream.
public static JavaDStream<List<Object>> twitterStream(JavaStreamingContext ctx, String username, String password, String accessToken, String secretToken, String[] filters, List<TwitterParameter> twitterParameters) {
twitter4j.conf.ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthAccessToken(accessToken);
builder.setOAuthAccessTokenSecret(secretToken);
builder.setOAuthConsumerKey(username);
builder.setOAuthConsumerSecret(password);
JavaDStream<Status> inputDStream = null;
if (filters.length > 0) {
if (filters.length == 1 && filters[0].equals(""))
inputDStream = TwitterUtils.createStream(ctx, new OAuthAuthorization(builder.build()));
else
inputDStream = TwitterUtils.createStream(ctx, new OAuthAuthorization(builder.build()), filters);
return inputDStream.map(new LoadTwitterFunction(twitterParameters));
}
return null;
}
Aggregations