Search in sources :

Example 81 with Twitter

use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.

the class RetweetersFragment method findUsers.

@Override
protected List<User> findUsers(long tweetId) {
    Twitter twitter = Utils.getTwitter(context, settings);
    List<User> users = new ArrayList<User>();
    try {
        Status stat = twitter.showStatus(tweetId);
        if (stat.isRetweet()) {
            tweetId = stat.getRetweetedStatus().getId();
        }
        // can get 100 retweeters is all
        ResponseList<Status> lists = twitter.getRetweets(tweetId);
        for (Status status : lists) {
            users.add(status.getUser());
        }
    } catch (Exception e) {
    }
    return users;
}
Also used : Status(twitter4j.Status) User(twitter4j.User) ArrayList(java.util.ArrayList) Twitter(twitter4j.Twitter)

Example 82 with Twitter

use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.

the class ProfilePicturesFragment method doSearch.

public void doSearch() {
    spinner.setVisibility(View.VISIBLE);
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                ResponseList<Status> result;
                try {
                    result = twitter.getUserTimeline(screenName, paging);
                } catch (OutOfMemoryError e) {
                    return;
                }
                tweets.clear();
                for (twitter4j.Status status : result) {
                    tweets.add(status);
                }
                if (result.size() > 17) {
                    hasMore = true;
                } else {
                    hasMore = false;
                }
                for (Status s : tweets) {
                    String[] links = TweetLinkUtils.getLinksInStatus(s);
                    if (!links[1].equals("")) {
                        pics.add(links[1]);
                        tweetsWithPics.add(s);
                    }
                }
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        Display display = ((Activity) context).getWindowManager().getDefaultDisplay();
                        Point size = new Point();
                        display.getSize(size);
                        int width = size.x;
                        int numColumns;
                        int currentOrientation = getResources().getConfiguration().orientation;
                        if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
                            numColumns = 5;
                        } else {
                            numColumns = 3;
                        }
                        adapter = new PicturesGridAdapter(context, pics, tweetsWithPics, width / numColumns);
                        listView.setAdapter(adapter);
                        listView.setVisibility(View.VISIBLE);
                        spinner.setVisibility(View.GONE);
                        canRefresh = true;
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                        canRefresh = false;
                    }
                });
            }
        }
    }).start();
}
Also used : Status(twitter4j.Status) PicturesGridAdapter(com.klinker.android.twitter.adapters.PicturesGridAdapter) Twitter(twitter4j.Twitter) Activity(android.app.Activity) Point(android.graphics.Point) Status(twitter4j.Status) Display(android.view.Display)

Example 83 with Twitter

use of twitter4j.Twitter in project AndroidSDK-RecipeBook by gabu.

the class Auth method onOKButton.

// OKボタンが押されたら呼び出される
public void onOKButton(View view) {
    // 入力されたユーザIDとパスワードを取得
    String userID = ((EditText) findViewById(R.id.user_id)).getText().toString();
    String password = ((EditText) findViewById(R.id.password)).getText().toString();
    // とりあえずユーザIDとパスワードでTwitterインスタンスを生成
    Twitter twitter = new TwitterFactory().getInstance(userID, password);
    try {
        // AccessTokenを取得
        AccessToken accessToken = twitter.getOAuthAccessToken();
        // tokenとtokenSecretを取得
        String token = accessToken.getToken();
        String tokenSecret = accessToken.getTokenSecret();
        // プリファレンスのEditorを取得
        Editor e = getSharedPreferences(Recipe102.PREF_NAME, MODE_PRIVATE).edit();
        // tokenとtokenSecretを書き込んで
        e.putString(Recipe102.PREF_KEY_TOKEN, token);
        e.putString(Recipe102.PREF_KEY_TOKEN_SECRET, tokenSecret);
        // 保存!
        e.commit();
        // Authアクティビティを終了
        finish();
    } catch (TwitterException e) {
        e.printStackTrace();
        Toast.makeText(getApplicationContext(), "ユーザIDかパスワードが間違っています。", Toast.LENGTH_SHORT).show();
    }
}
Also used : AccessToken(twitter4j.http.AccessToken) Twitter(twitter4j.Twitter) TwitterFactory(twitter4j.TwitterFactory) Editor(android.content.SharedPreferences.Editor) TwitterException(twitter4j.TwitterException)

Example 84 with Twitter

use of twitter4j.Twitter 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 85 with Twitter

use of twitter4j.Twitter in project camel by apache.

the class SearchConsumer method search.

private List<Exchange> search(Query query) throws TwitterException {
    Integer numberOfPages = 1;
    if (ObjectHelper.isNotEmpty(endpoint.getProperties().getLang())) {
        query.setLang(endpoint.getProperties().getLang());
    }
    if (ObjectHelper.isNotEmpty(endpoint.getProperties().getCount())) {
        query.setCount(endpoint.getProperties().getCount());
    }
    if (ObjectHelper.isNotEmpty(endpoint.getProperties().getNumberOfPages())) {
        numberOfPages = endpoint.getProperties().getNumberOfPages();
    }
    if (ObjectHelper.isNotEmpty(endpoint.getProperties().getLatitude()) && ObjectHelper.isNotEmpty(endpoint.getProperties().getLongitude()) && ObjectHelper.isNotEmpty(endpoint.getProperties().getRadius())) {
        GeoLocation location = new GeoLocation(endpoint.getProperties().getLatitude(), endpoint.getProperties().getLongitude());
        query.setGeoCode(location, endpoint.getProperties().getRadius(), Unit.valueOf(endpoint.getProperties().getDistanceMetric()));
        LOG.debug("Searching with additional geolocation parameters.");
    }
    LOG.debug("Searching with {} pages.", numberOfPages);
    Twitter twitter = getTwitter();
    QueryResult qr = twitter.search(query);
    List<Status> tweets = qr.getTweets();
    for (int i = 1; i < numberOfPages; i++) {
        if (!qr.hasNext()) {
            break;
        }
        qr = twitter.search(qr.nextQuery());
        tweets.addAll(qr.getTweets());
    }
    if (endpoint.getProperties().isFilterOld()) {
        for (int i = 0; i < tweets.size(); i++) {
            setLastIdIfGreater(tweets.get(i).getId());
        }
    }
    return TwitterEventType.STATUS.createExchangeList(endpoint, tweets);
}
Also used : Status(twitter4j.Status) QueryResult(twitter4j.QueryResult) Twitter(twitter4j.Twitter) GeoLocation(twitter4j.GeoLocation) TwitterEndpoint(org.apache.camel.component.twitter.TwitterEndpoint)

Aggregations

Twitter (twitter4j.Twitter)127 TwitterException (twitter4j.TwitterException)76 TwitterFactory (twitter4j.TwitterFactory)60 Status (twitter4j.Status)44 Activity (android.app.Activity)35 QueryResult (twitter4j.QueryResult)17 TimelineArrayAdapter (com.klinker.android.twitter.adapters.TimelineArrayAdapter)16 Intent (android.content.Intent)13 ArrayList (java.util.ArrayList)13 User (twitter4j.User)12 Query (twitter4j.Query)11 IDs (twitter4j.IDs)8 LinearLayout (android.widget.LinearLayout)7 IOException (java.io.IOException)7 Context (android.content.Context)6 DrawerActivity (com.klinker.android.twitter.activities.drawer_activities.DrawerActivity)6 LoginActivity (com.klinker.android.twitter.activities.setup.LoginActivity)6 AppSettings (com.klinker.android.twitter.settings.AppSettings)5 GeoLocation (twitter4j.GeoLocation)5 Paging (twitter4j.Paging)5