Ejemplo n.º 1
0
  public static void main(String args[]) {
    try {
      ConfigurationBuilder cb = new ConfigurationBuilder();
      cb.setDebugEnabled(true)
          .setOAuthConsumerKey(cK)
          .setOAuthConsumerSecret(cS)
          .setOAuthAccessToken(aT)
          .setOAuthAccessTokenSecret(aTS);

      TwitterFactory tf = new TwitterFactory(cb.build());
      Twitter twitter = tf.getInstance();
      long cursor = -1;
      long IDS = 2458351900L;
      IDs ids;
      System.out.println("Listing followers's ids.");
      do {
        ids = twitter.getFollowersIDs(IDS, cursor);

        for (long id : ids.getIDs()) {
          System.out.println(id);
        }
      } while ((cursor = ids.getNextCursor()) != 0);
      System.exit(0);
    } catch (TwitterException te) {
      te.printStackTrace();
      System.out.println("Failed to get followers' ids: " + te.getMessage());
      System.exit(-1);
    }
  }
Ejemplo n.º 2
0
  private void getTweetsFromTwitter() {
    try {
      ConfigurationBuilder confbuilder = new ConfigurationBuilder();
      confbuilder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
      confbuilder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);

      // Access Token
      String access_token = mSharedPreferences.getString(PREF_KEY_OAUTH_TOKEN, "");
      // Access Token Secret
      String access_token_secret = mSharedPreferences.getString(PREF_KEY_OAUTH_SECRET, "");

      AccessToken accessToken = new AccessToken(access_token, access_token_secret);

      btnLogoutTwitter.setVisibility(View.GONE);
      btnGetTweets.setVisibility(View.GONE);
      lblUserName.setVisibility(View.GONE);
      btnShowOnMap.setVisibility(View.GONE);
      btnUsers.setVisibility(View.GONE);

      Twitter twitter = new TwitterFactory(confbuilder.build()).getInstance(accessToken);
      List<Status> statuses = twitter.getUserTimeline(USER_ID, new Paging(1, 10));

      IDs following = twitter.getFriendsIDs(USER_ID);

      long[] followingList = following.getIDs();

      for (int i = 0; i < followingList.length; i++) {

        Toast.makeText(getApplicationContext(), twitter.showUser(followingList[i]).toString(), 100)
            .show();
      }

      int count = 0;
      // Collections.reverse(statuses); // reverse order
      ArrayList<String> arrayList = new ArrayList<String>();
      for (Status status : statuses) {
        String tweettext =
            status.getUser().getName()
                + ":"
                + status.getText()
                + "\n ("
                + status.getCreatedAt().toLocaleString()
                + ")"
                + status.getGeoLocation();
        arrayList.add(tweettext);

        // now single tweet is in tweettext
      }

      ListView lv = (ListView) findViewById(R.id.storeTweet);
      ArrayAdapter<String> arrayAdapter =
          new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arrayList);

      lv.setAdapter(arrayAdapter);
    } catch (Exception ex) {
      // failed to fetch tweet
    }
  }
Ejemplo n.º 3
0
  private static void getTwitterProfileInfo(AccessToken accessToken2) {
    try {
      String token = accessToken2.getToken();
      Log.i(TAG, "token is " + token);
      mUserInfo.setExtra(token);
      long userId = accessToken2.getUserId();
      mUserInfo.setTwitterId(String.valueOf(userId));
      userObj = twitter.showUser(userId);
      mUserInfo.setProfilePic(userObj.getBiggerProfileImageURLHttps());
      long cursor = -1;
      IDs freinds = twitter.getFriendsIDs(userObj.getId(), cursor);
      Log.d(TAG, "IDS:" + freinds.getIDs());
      if (freinds.getIDs() != null) {
        StringBuilder builder = new StringBuilder();
        builder.append("");
        do {
          for (long i : freinds.getIDs()) {

            builder.append(i + ",");
          }
        } while (freinds.hasNext());
        String freindIds = builder.toString();
        Log.d("MSG:", "FND id:" + freindIds);
        if (freindIds.equals("")) {
          mUserInfo.setFriendsIds(freindIds);
        } else {
          freindIds = freindIds.substring(0, freindIds.length() - 1);
          mUserInfo.setFriendsIds(freindIds);
        }
      }
      if (userObj.getName() != null) {
        String name[] = userObj.getName().split(" ");
        /*
         * mUserInfo.setFirstName(name[0]); if (name[1] != null) {
         * mUserInfo.setLastName(name[1]);
         *
         * }
         */
        if (name.length >= 2) {
          mUserInfo.setFirstName(name[0]);
          mUserInfo.setLastName(name[1]);
        } else if (name.length >= 1) {
          mUserInfo.setFirstName(name[0]);
        }
      }

      mUserInfo.setExpiresIn(String.valueOf(System.currentTimeMillis() + 600000));

    } catch (TwitterException e) {
      Log.e(TAG, "Twitter login error");
    }

    twitterHandler.isExit(String.valueOf(accessToken2.getUserId()));
  }
Ejemplo n.º 4
0
 @Override
 public List<User> getUsers(final Twitter twitter) throws TwitterException {
   if (twitter == null) return null;
   final CursorPaging paging = new CursorPaging(getCount());
   if (getCursor() > 0) {
     paging.setCursor(getCursor());
   }
   final IDs ids = getIDs(twitter, paging);
   if (ids == null) return null;
   setCursorIds(ids);
   return twitter.lookupUsers(ids.getIDs());
 }
Ejemplo n.º 5
0
 /** Remove all user's friendships (ie. people you are following). Note: Not time aware. */
 private void removeFriendships() {
   try {
     long cursor = -1;
     IDs ids;
     do {
       ids = twitter.getFriendsIDs(cursor);
       for (long id : ids.getIDs()) {
         twitter.destroyFriendship(id);
       }
     } while ((cursor = ids.getNextCursor()) != 0);
   } catch (TwitterException e) {
     logger.error("Twitter exception occurred", e);
   }
 }
  /**
   * Returns a list of id of the users the configured account follows. Returns null in case of
   * error.
   */
  public ArrayList<Long> getFollowing() {

    ArrayList<Long> following = new ArrayList<Long>();
    try {
      long lCursor = -1;
      IDs friendsIDs = twitter.getFriendsIDs(twitter.getId(), lCursor);
      do {
        for (long i : friendsIDs.getIDs()) {
          following.add(i);
        }
      } while (friendsIDs.hasNext());

      return following;
    } catch (Exception ex) {
      System.err.println("[ERROR] Can't get following users.");
      ex.printStackTrace();
      return null;
    }
  }
  public List<TwitterUsuarioId> getIdsUsuariosTwitter(Long idUsuarioTwitter, Twitter twitter)
      throws TwitterException {
    long cursor = -1;
    List<TwitterUsuarioId> listaDeId = new ArrayList<TwitterUsuarioId>();
    IDs ids = null;
    User user = null;
    do {
      // pode usar essa metodo passando como primeiro argumento os id´s e
      // como segundo argumento paginação para retornar os amigos do id repassado.
      ids = twitter.getFriendsIDs(idUsuarioTwitter, cursor);
      for (long id : ids.getIDs()) {
        TwitterUsuarioId idNovo = twitterUsuarioIdService.getTwitterUsuarioIdByIdTwitter(id);
        if (idNovo == null) {
          idNovo = new TwitterUsuarioId();
          idNovo.setIdTwitter(id);
          twitterUsuarioIdService.save(idNovo);
        }

        listaDeId.add(idNovo);
      }
    } while ((cursor = ids.getNextCursor()) != 0);
    return listaDeId;
  }
Ejemplo n.º 8
0
  /**
   * フォローしているユーザー/フォローされているユーザーの一覧を取得します。
   *
   * @param twitter
   * @param mode
   * @return
   */
  public static List<Long> getIdsString(Twitter twitter, int mode) {
    List<Long> idsData = new ArrayList<Long>();
    try {
      long cursor = -1;
      IDs workIds = null;
      long[] targetIds = null;
      do {
        if (mode == GETFRIENDS) { // modeによって呼び出すメソッドを変更
          workIds = twitter.getFriendsIDs(cursor);
        } else if (mode == GETFOLLOWERS) {
          workIds = twitter.getFollowersIDs(cursor);
        }
        targetIds = workIds.getIDs();
        for (int i = 0; i < targetIds.length; i++) {
          idsData.add(targetIds[i]);
        }
        cursor = workIds.getNextCursor();
      } while (cursor != 0);

    } catch (TwitterException e) {
      log.info(e.getMessage());
    }
    return idsData;
  }