Search in sources :

Example 1 with OAuthAuthorization

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;
}
Also used : Status(twitter4j.Status) ConfigurationBuilder(twitter4j.conf.ConfigurationBuilder) ConfigurationBuilder(twitter4j.conf.ConfigurationBuilder) LoadTwitterFunction(org.talend.spark.function.LoadTwitterFunction) OAuthAuthorization(twitter4j.auth.OAuthAuthorization)

Example 2 with OAuthAuthorization

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);
}
Also used : Authorization(twitter4j.auth.Authorization) OAuth2Authorization(twitter4j.auth.OAuth2Authorization) OAuthAuthorization(twitter4j.auth.OAuthAuthorization) NullAuthorization(twitter4j.auth.NullAuthorization) OAuthAuthorization(twitter4j.auth.OAuthAuthorization) Test(org.junit.jupiter.api.Test)

Example 3 with 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);
}
Also used : OAuthAuthorization(twitter4j.auth.OAuthAuthorization)

Example 4 with OAuthAuthorization

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);
}
Also used : OAuthAuthorization(twitter4j.auth.OAuthAuthorization)

Example 5 with OAuthAuthorization

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;
}
Also used : AccessToken(twitter4j.auth.AccessToken) OAuthAuthorization(twitter4j.auth.OAuthAuthorization)

Aggregations

OAuthAuthorization (twitter4j.auth.OAuthAuthorization)6 Test (org.junit.jupiter.api.Test)1 LoadTwitterFunction (org.talend.spark.function.LoadTwitterFunction)1 Status (twitter4j.Status)1 AccessToken (twitter4j.auth.AccessToken)1 Authorization (twitter4j.auth.Authorization)1 NullAuthorization (twitter4j.auth.NullAuthorization)1 OAuth2Authorization (twitter4j.auth.OAuth2Authorization)1 ConfigurationBuilder (twitter4j.conf.ConfigurationBuilder)1