Search in sources :

Example 1 with Configuration

use of twitter4j.conf.Configuration in project ddf by codice.

the class TwitterSource method init.

public void init() {
    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    Configuration configuration = configurationBuilder.setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret).setApplicationOnlyAuthEnabled(true).build();
    twitterFactory = new TwitterFactory(configuration);
}
Also used : ConfigurationBuilder(twitter4j.conf.ConfigurationBuilder) Configuration(twitter4j.conf.Configuration) TwitterFactory(twitter4j.TwitterFactory)

Example 2 with Configuration

use of twitter4j.conf.Configuration in project twicalico by moko256.

the class GlobalApplication method getTwitterInstance.

@NonNull
public Twitter getTwitterInstance(@NonNull AccessToken accessToken) {
    Twitter t;
    Configuration conf;
    if (accessToken.getType() == Type.TWITTER) {
        conf = new ConfigurationBuilder().setTweetModeExtended(true).setOAuthConsumerKey(BuildConfig.CONSUMER_KEY).setOAuthConsumerSecret(BuildConfig.CONSUMER_SECRET).setOAuthAccessToken(accessToken.getToken()).setOAuthAccessTokenSecret(accessToken.getTokenSecret()).build();
        t = twitterCache.get(conf);
        if (t == null) {
            t = new TwitterFactory(conf).getInstance();
            twitterCache.put(conf, t);
        }
    } else {
        conf = new ConfigurationBuilder().setOAuthAccessToken(accessToken.getToken()).setRestBaseURL(accessToken.getUrl()).build();
        t = twitterCache.get(conf);
        if (t == null) {
            t = new MastodonTwitterImpl(conf, accessToken.getUserId(), getOkHttpClient(conf.getHttpClientConfiguration()).newBuilder());
            twitterCache.put(conf, t);
        }
    }
    return t;
}
Also used : ConfigurationBuilder(twitter4j.conf.ConfigurationBuilder) AppConfiguration(com.github.moko256.twicalico.config.AppConfiguration) HttpClientConfiguration(twitter4j.HttpClientConfiguration) Configuration(twitter4j.conf.Configuration) Twitter(twitter4j.Twitter) TwitterFactory(twitter4j.TwitterFactory) MastodonTwitterImpl(com.github.moko256.mastodon.MastodonTwitterImpl) NonNull(android.support.annotation.NonNull)

Example 3 with Configuration

use of twitter4j.conf.Configuration in project AndroidSDK-RecipeBook by gabu.

the class Recipe102 method onResume.

public void onResume() {
    super.onResume();
    // プリファレンスを取得
    SharedPreferences sp = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
    // tokenとtokenSecretを取得
    String token = sp.getString(PREF_KEY_TOKEN, "");
    String tokenSecret = sp.getString(PREF_KEY_TOKEN_SECRET, "");
    // 値がなければAuthアクティビティを起動
    if ("".equals(token) || "".equals(tokenSecret)) {
        Intent intent = new Intent(this, Auth.class);
        startActivity(intent);
    }
    // twitter4jのConfigurationを取得
    Configuration conf = ConfigurationContext.getInstance();
    // AccessTokenを生成
    AccessToken accessToken = new AccessToken(token, tokenSecret);
    // OAuthAuthorizationを生成
    Authorization auth = new OAuthAuthorization(conf, conf.getOAuthConsumerKey(), conf.getOAuthConsumerSecret(), accessToken);
    // OAuthAuthorizationを使ってTwitterインスタンスを生成
    Twitter twitter = new TwitterFactory().getInstance(auth);
    try {
        // とりあえずテストのためTLをログ出力
        ResponseList<Status> statuses = twitter.getHomeTimeline();
        for (Status status : statuses) {
            Log.d(TAG, status.getUser().getName() + ":" + status.getText());
        }
    } catch (TwitterException e) {
        e.printStackTrace();
    }
}
Also used : Authorization(twitter4j.http.Authorization) OAuthAuthorization(twitter4j.http.OAuthAuthorization) Status(twitter4j.Status) Configuration(twitter4j.conf.Configuration) SharedPreferences(android.content.SharedPreferences) AccessToken(twitter4j.http.AccessToken) Twitter(twitter4j.Twitter) Intent(android.content.Intent) TwitterFactory(twitter4j.TwitterFactory) OAuthAuthorization(twitter4j.http.OAuthAuthorization) TwitterException(twitter4j.TwitterException)

Example 4 with Configuration

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

the class MediaUploadTest method testProviders.

public void testProviders() throws Exception {
    Configuration conf;
    conf = new ConfigurationBuilder().setMediaProvider(MediaProvider.TWITTER.name()).build();
    new ImageUploadFactory(conf);
    conf = new ConfigurationBuilder().setMediaProvider(MediaProvider.IMG_LY.name()).build();
    new ImageUploadFactory(conf);
    conf = new ConfigurationBuilder().setMediaProvider(MediaProvider.TWIPPLE.name()).build();
    new ImageUploadFactory(conf);
    conf = new ConfigurationBuilder().setMediaProvider(MediaProvider.MOBYPICTURE.name()).build();
    new ImageUploadFactory(conf);
}
Also used : ConfigurationBuilder(twitter4j.conf.ConfigurationBuilder) Configuration(twitter4j.conf.Configuration)

Example 5 with Configuration

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

the class SiteStreamsTest method testSiteStream.

public void testSiteStream() throws Exception {
    InputStream is = SiteStreamsTest.class.getResourceAsStream("/sitestream-test.properties");
    if (null == is) {
        System.out.println("sitestream-test.properties not found. skipping Site Streams test.");
    } else {
        Properties props = new Properties();
        props.load(is);
        is.close();
        Configuration yusukeyConf = new PropertyConfiguration(props, "/yusukey");
        Configuration twit4jConf = new PropertyConfiguration(props, "/id1");
        Configuration twit4j2Conf = new PropertyConfiguration(props, "/id2");
        TwitterStream twitterStream = new TwitterStreamFactory(yusukeyConf).getInstance();
        twitterStream.addListener(this);
        Twitter twit4j = new TwitterFactory(twit4jConf).getInstance();
        Twitter twit4j2 = new TwitterFactory(twit4j2Conf).getInstance();
        try {
            twit4j.destroyBlock(6377362);
        } catch (TwitterException ignore) {
        }
        try {
            twit4j2.destroyBlock(6358482);
        } catch (TwitterException ignore) {
        }
        try {
            twit4j.createFriendship(6377362);
        } catch (TwitterException ignore) {
        }
        try {
            twit4j2.createFriendship(6358482);
        } catch (TwitterException ignore) {
        }
        //twit4j: 6358482
        //twit4j2: 6377362
        StreamController cs = twitterStream.site(true, 6377362, 4933401);
        //expecting onFriendList for twit4j and twit4j2
        waitForStatus("onFriendList");
        ControlStreamInfo info = cs.getInfo();
        assertEquals(2, info.getUsers().length);
        cs.addUsers(6358482L);
        waitForStatus("new User");
        info = cs.getInfo();
        assertEquals(3, info.getUsers().length);
        StreamController.FriendsIDs ids = cs.getFriendsIDs(4933401L, -1);
        assertTrue(ids.getIds().length > 100);
        assertEquals("yusuke", ids.getUser().getName());
        cs.removeUsers(4933401L);
        waitForStatus("remove user");
        Status status = twit4j2.updateStatus("@twit4j " + new Date());
        //expecting onStatus for twit4j from twit4j
        waitForStatus("update status");
        twit4j.createFavorite(status.getId());
        waitForStatus("crate favorite");
        twit4j.destroyFavorite(status.getId());
        waitForStatus("destroy favorite");
        // unfollow twit4j
        twit4j2.destroyFriendship(6358482);
        waitForStatus("destroy friendship");
        // follow twit4j
        twit4j2.createFriendship(6358482);
        waitForStatus("create friendship");
        // unfollow twit4j2
        twit4j.destroyFriendship(6377362);
        // follow twit4j2
        twit4j.createFriendship(6377362);
        waitForStatus("create friendship");
        twit4j.retweetStatus(status.getId());
        waitForStatus("retweeet status");
        DirectMessage dm = twit4j.sendDirectMessage(42419133, "test " + new Date());
        waitForStatus("dm");
        twitter2.destroyStatus(status.getId());
        waitForStatus("destory status");
        //            twitter1.destroyDirectMessage(dm.getId());
        //            waitForStatus();
        // block twit4j
        twit4j2.createBlock(6358482);
        waitForStatus("create block");
        // unblock twit4j
        twit4j2.destroyBlock(6358482);
        waitForStatus("destroy block");
        try {
            twit4j.createFriendship(6377362);
            waitForStatus("create friendship");
        } catch (TwitterException ignore) {
        }
        try {
            twit4j2.createFriendship(6358482);
            waitForStatus("create friendship");
        } catch (TwitterException ignore) {
        }
        twitter1.updateProfile(null, null, new Date().toString(), null);
        waitForStatus("update profile");
        UserList list = twit4j.createUserList("test", true, "desctription");
        waitForStatus("create userlist");
        list = twit4j.updateUserList(list.getId(), "test2", true, "description2");
        waitForStatus("update userlist");
        twit4j.createUserListMember(list.getId(), id2.id);
        waitForStatus("create userlist member");
        twit4j2.createUserListSubscription(list.getId());
        waitForStatus("create userlist subscription");
        twit4j2.destroyUserListSubscription(list.getId());
        waitForStatus("destroy userlist subscription");
        twit4j.destroyUserListMember(list.getId(), id2.id);
        waitForStatus("destroy userlist member");
        twit4j.destroyUserList(list.getId());
        waitForStatus("destroy userlist");
        assertReceived("onstatus", "onstatus");
        assertReceived("onfriendlist", "onfriendlist");
        assertReceived("onFavorite", TwitterMethod.CREATE_FAVORITE);
        assertReceived("onUnfavorite", TwitterMethod.DESTROY_FAVORITE);
        //            assertReceived(TwitterMethod.RETWEET_STATUS);
        //            assertReceived("onDirectMessage", TwitterMethod.SEND_DIRECT_MESSAGE);
        assertReceived("onDeletionNotice-status", TwitterMethod.DESTROY_STATUS);
        //            assertReceived("onDeletionNotice-directmessage", TwitterMethod.DESTROY_DIRECT_MESSAGE);
        assertReceived("onUserListMemberAddition", TwitterMethod.CREATE_LIST_MEMBER);
        assertReceived("onUserListMemberDeletion", TwitterMethod.DESTROY_LIST_MEMBER);
        assertReceived("onUserListSubscribed", TwitterMethod.SUBSCRIBE_LIST);
        assertReceived("onUserListUnsubscribed", TwitterMethod.UNSUBSCRIBE_LIST);
        assertReceived("onUserListCreated", TwitterMethod.CREATE_USER_LIST);
        assertReceived("onUserListUpdated", TwitterMethod.UPDATE_USER_LIST);
        assertReceived("onUserListDestoyed", TwitterMethod.DESTROY_USER_LIST);
        assertReceived("onUserProfileUpdated", TwitterMethod.UPDATE_PROFILE);
        assertReceived("onBlock", TwitterMethod.CREATE_BLOCK);
        assertReceived("onUnblock", TwitterMethod.DESTROY_BLOCK);
        assertReceived("onFollow", TwitterMethod.CREATE_FRIENDSHIP);
        assertReceived("onUnfollow", TwitterMethod.DESTROY_FRIENDSHIP);
    }
}
Also used : Configuration(twitter4j.conf.Configuration) PropertyConfiguration(twitter4j.conf.PropertyConfiguration) InputStream(java.io.InputStream) Properties(java.util.Properties) Date(java.util.Date) PropertyConfiguration(twitter4j.conf.PropertyConfiguration)

Aggregations

Configuration (twitter4j.conf.Configuration)7 ConfigurationBuilder (twitter4j.conf.ConfigurationBuilder)5 TwitterFactory (twitter4j.TwitterFactory)4 Intent (android.content.Intent)2 InputStream (java.io.InputStream)2 Date (java.util.Date)2 Twitter (twitter4j.Twitter)2 TwitterException (twitter4j.TwitterException)2 PropertyConfiguration (twitter4j.conf.PropertyConfiguration)2 AlarmManager (android.app.AlarmManager)1 AlertDialog (android.app.AlertDialog)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 SharedPreferences (android.content.SharedPreferences)1 NonNull (android.support.annotation.NonNull)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