use of twitter4j.auth.OAuthAuthorization 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;
}
use of twitter4j.auth.OAuthAuthorization in project twitter4j by yusuke.
the class AuthorizationTest method testOAuthInstance.
@Test
void testOAuthInstance() throws Exception {
String consumerSecret;
String consumerKey;
consumerSecret = p.getProperty("browser.oauth.consumerSecret");
consumerKey = p.getProperty("browser.oauth.consumerSecret");
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(consumerKey, consumerSecret);
try {
twitter.setOAuthConsumer(consumerSecret, consumerKey);
fail("should throw IllegalStateException");
} catch (IllegalStateException ignore) {
}
Authorization auth = twitter.getAuthorization();
assertTrue(auth instanceof OAuthAuthorization);
}
use of twitter4j.auth.OAuthAuthorization in project twitter4j by yusuke.
the class TwitterFactory method getInstance.
/**
* Returns a OAuth Authenticated instance.<br>
* consumer key and consumer Secret must be provided by twitter4j.properties, or system properties.<br>
* Unlike {@link Twitter#setOAuthAccessToken(twitter4j.auth.AccessToken)}, this factory method potentially returns a cached instance.
*
* @param accessToken access token
* @return an instance
* @since Twitter4J 2.1.9
*/
public Twitter getInstance(AccessToken accessToken) {
String consumerKey = conf.getOAuthConsumerKey();
String consumerSecret = conf.getOAuthConsumerSecret();
if (null == consumerKey && null == consumerSecret) {
throw new IllegalStateException("Consumer key and Consumer secret not supplied.");
}
OAuthAuthorization oauth = new OAuthAuthorization(conf);
oauth.setOAuthAccessToken(accessToken);
return getInstance(oauth);
}
use of twitter4j.auth.OAuthAuthorization in project twitter4j by yusuke.
the class TwitterStreamFactory method getInstance.
/**
* Returns a OAuth Authenticated instance.<br>
* consumer key and consumer Secret must be provided by twitter4j.properties, or system properties.
* Unlike {@link TwitterStream#setOAuthAccessToken(twitter4j.auth.AccessToken)}, this factory method potentially returns a cached instance.
*
* @param accessToken access token
* @return an instance
*/
public TwitterStream getInstance(AccessToken accessToken) {
String consumerKey = conf.getOAuthConsumerKey();
String consumerSecret = conf.getOAuthConsumerSecret();
if (null == consumerKey && null == consumerSecret) {
throw new IllegalStateException("Consumer key and Consumer secret not supplied.");
}
OAuthAuthorization oauth = new OAuthAuthorization(conf);
oauth.setOAuthAccessToken(accessToken);
return getInstance(conf, oauth);
}
use of twitter4j.auth.OAuthAuthorization in project twitter4j by yusuke.
the class DAOTest method getOAuthOuthorization.
private OAuthAuthorization getOAuthOuthorization(Configuration conf) {
OAuthAuthorization oauth = new OAuthAuthorization(conf);
oauth.setOAuthConsumer(desktopConsumerKey, desktopConsumerSecret);
oauth.setOAuthAccessToken(new AccessToken(id1.accessToken, id1.accessTokenSecret));
return oauth;
}
Aggregations