public void removeAllUserList() { // {{{
   Set<String> set = userlists.keySet();
   Iterator iter = set.iterator();
   while (iter.hasNext()) {
     UserList list = userlists.get(iter.next());
     getLayout().removeLayoutComponent(panels.get(list.getName()));
   }
   panels.clear();
   userlists.clear();
 } // }}}
  /**
   * Remove all user lists irrelevant of creation date since that information is not exposed via
   * twitter/ twitter4j. Note: Not time aware.
   */
  private void removeLists() {
    try {
      ResponseList<UserList> lists = twitter.getUserLists(twitter.getScreenName());
      for (UserList list : lists) {
        twitter.destroyUserList(list.getId());
      }

    } catch (TwitterException e) {
      logger.error("Twitter exception occurred", e);
    }
  }
Beispiel #3
0
 /**
  * Usage: java twitter4j.examples.list.DestroyUserList [list id]
  *
  * @param args message
  */
 public static void main(String[] args) {
   if (args.length < 1) {
     System.out.println("Usage: java twitter4j.examples.list.DestroyUserList [list id]");
     System.exit(-1);
   }
   try {
     Twitter twitter = new TwitterFactory().getInstance();
     UserList list = twitter.destroyUserList(Integer.parseInt(args[0]));
     System.out.println(
         "Successfully deleted the list (id:" + list.getId() + ", slug:" + list.getSlug() + ").");
     System.exit(0);
   } catch (TwitterException te) {
     te.printStackTrace();
     System.out.println("Failed to delete a list: " + te.getMessage());
     System.exit(-1);
   }
 }
Beispiel #4
0
 /** Synchronize lists between what is available in the db and on twitter. */
 private void syncLists() {
   TwitterHelper th = new TwitterHelper(this, account);
   TweetDB tdb = new TweetDB(this, accountId);
   if (account.getServerType().equalsIgnoreCase("twitter")) {
     List<UserList> userLists = th.getUserLists();
     Map<String, Integer> storedLists = tdb.getLists();
     // Check for lists to add
     for (UserList userList : userLists) {
       if (!storedLists.containsValue(userList.getId())) {
         tdb.addList(userList.getName(), userList.getId(), DataObjectFactory.getRawJSON(userList));
       }
     }
     // check for outdated lists and remove them
     for (Entry<String, Integer> entry : storedLists.entrySet()) {
       Integer id = entry.getValue();
       boolean found = false;
       for (UserList userList2 : userLists) {
         if (userList2.getId() == id) {
           found = true;
           break;
         }
       }
       if (!found) {
         tdb.removeList(id);
       }
     }
     syncSearches(th, tdb);
   }
 }
  public UserListPanel addUserList(UserList list) // {{{
      {
    UserListPanel panel = null;
    try {
      panel = new UserListPanel();
      panel.setSessionName(sessionName);
      panel.setTitle(list.getName());
      // Lets make sure that the TwitzMainView is a TwitzEventListener for this and all panels
      // We add it first here because setUserList causes a TwitzEvent to be fired to get the list
      // users
      panel.addTwitzListener(view);
      panel.addPropertyChangeListener("collapsed", this);

      panel.setUserList(list);

      addPanel(panel);
      userlists.put(list.getName(), list);
      panels.put(list.getName(), panel);
    } catch (Exception e) {
      logger.error("Error while adding UserListPanel", e);
    }
    // panel.setCollapsed(true);
    return panel;
  } // }}}
  public void testSchema() throws Exception {
    String[] schema;
    String url;

    //        JSONObject json = new
    // JSONObject("{\"a\":\"avalue\",\"b\":\"bvalue\",\"c\":{\"c-1\":12,\"c-2\":\"c-2value\"}}");
    //        schema = new String[]{"a", "b", "c/c-1", "c/c-2"};
    //        validateJSONObjectSchema(json, schema);
    //        try {
    //            schema = new String[]{"a", "b", "c/c-1"};
    //            validateJSONObjectSchema(json, schema);
    //            fail("c/c-2 is missing. expecting an AssertionFailedError.");
    //        } catch (AssertionFailedError ignore) {
    ////            ignore.printStackTrace();
    //        }
    //        try {
    //            schema = new String[]{"a", "b"};
    //            validateJSONObjectSchema(json, schema);
    //            fail("c is missing. expecting an AssertionFailedError.");
    //        } catch (AssertionFailedError ignore) {
    ////            ignore.printStackTrace();
    //        }
    //        try {
    //            schema = new String[]{"a", "b","c"};
    //            validateJSONObjectSchema(json, schema);
    //            fail("c/* is missing. expecting an AssertionFailedError.");
    //        } catch (AssertionFailedError ignore) {
    ////            ignore.printStackTrace();
    //        }
    //        schema = new String[]{"a", "b", "c/*"};
    //        validateJSONObjectSchema(json, schema);
    //
    //        JSONArray array = new JSONArray("[{\"slug\":\"art-design\",\"name\":\"Art &
    // Design\"},{\"slug\":\"books\",\"name\":\"Books\"}]");
    //        schema = new String[]{"slug", "name"};
    //        validateJSONArraySchema(array, schema);

    // Location

    //        schema = new
    // String[]{"url","country","woeid","placeType/name","placeType/code","name","countryCode"};
    //        url = "http://api.twitter.com/1.1/trends/available.json";
    //        validateJSONArraySchema(url, schema);
    // Place
    if (!Boolean.valueOf(System.getProperties().getProperty("twitter4j.test.schema"))) {
      // skipping schema validation
      return;
    }

    schema =
        new String[] {
          "slug", "name", "size",
        };
    url = "http://api.twitter.com/1.1/users/suggestions.json";
    List categories =
        CategoryJSONImpl.createCategoriesList(validateJSONArraySchema(url, schema), null, conf);
    Assert.assertEquals(20, categories.size());

    schema = new String[] {"slug", "name", "size", "categories/*", "users/*"};
    url = "http://api.twitter.com/1.1/users/suggestions/art-design.json";
    validateJSONObjectSchema(url, schema);

    schema =
        new String[] {
          "result/places/name",
          "result/places/street_address",
          "result/places/attributes/*",
          "result/places/country_code",
          "result/places/id",
          "result/places/country",
          "result/places/place_type",
          "result/places/url",
          "result/places/full_name",
          "result/places/bounding_box/*",
          "result/places/contained_within/place_type",
          "result/places/contained_within/attributes/*",
          "result/places/contained_within/street_address",
          "result/places/contained_within/url",
          "result/places/contained_within/bounding_box/type",
          "result/places/contained_within/bounding_box/coordinates/*",
          "result/places/contained_within/full_name",
          "result/places/contained_within/country_code",
          "result/places/contained_within/name",
          "result/places/contained_within/id",
          "result/places/contained_within/country",
          "query",
          "query/type",
          "query/url",
          "query/params",
          "query/params/granularity",
          "query/params/coordinates",
          "query/params/coordinates/type",
          "query/params/coordinates/coordinates",
          "query/params/coordinates/coordinates/*",
          "query/params/accuracy",
        };
    url = "http://api.twitter.com/1.1/geo/reverse_geocode.json?lat=37.78215&long=-122.40060";
    validateJSONObjectSchema(url, schema);

    schema =
        new String[] {
          "next_cursor",
          "next_cursor_str",
          "previous_cursor",
          "previous_cursor_str",
          "lists/id",
          "lists/id_str",
          "lists/member_count",
          "lists/description",
          "lists/name",
          "lists/subscriber_count",
          "lists/slug",
          "lists/user/*",
          "lists/uri",
          "lists/full_name",
          "lists/mode",
          "lists/following",
        };
    url = "http://api.twitter.com/1.1/twit4j2/lists.json";
    validateJSONObjectSchema(url, schema);

    schema =
        new String[] {
          "id",
          "id_str",
          "member_count",
          "description",
          "name",
          "subscriber_count",
          "slug",
          "user/*",
          "uri",
          "full_name",
          "mode",
          "following",
        };
    url = "http://api.twitter.com/1.1/twit4j2/lists/9499823.json";
    UserList userList = new UserListJSONImpl(validateJSONObjectSchema(url, schema));
    Assert.assertEquals("", userList.getDescription());
    Assert.assertEquals("@twit4j2/test", userList.getFullName());
    Assert.assertEquals(9499823, userList.getId());
    Assert.assertTrue(1 < userList.getMemberCount());
    Assert.assertEquals("test", userList.getName());
    Assert.assertEquals("test", userList.getSlug());
    Assert.assertEquals(0, userList.getSubscriberCount());
    Assert.assertEquals("/twit4j2/test", userList.getURI().toString());
    Assert.assertNotNull(userList.getUser());
    Assert.assertTrue(userList.isPublic());
    Assert.assertFalse(userList.isFollowing());

    schema =
        new String[] {
          "favorited",
          "in_reply_to_status_id",
          "in_reply_to_status_id_str",
          "created_at",
          "geo",
          "place",
          "source",
          "in_reply_to_screen_name",
          "in_reply_to_user_id",
          "in_reply_to_user_id_str",
          "coordinates",
          "truncated",
          "contributors",
          "id",
          "id_str",
          "text",
          "user/*",
          "retweeted",
          "retweet_count"
        };
    url = "http://api.twitter.com/1.1/statuses/show/2245071380.json";
    Status status = new StatusJSONImpl(validateJSONObjectSchema(url, schema));

    schema =
        new String[] {
          "profile_background_image_url",
          "created_at",
          "friends_count",
          "profile_link_color",
          "description",
          "contributors_enabled",
          "status/*",
          "following",
          "profile_background_tile",
          "favourites_count",
          "profile_sidebar_fill_color",
          "url",
          "profile_image_url",
          "geo_enabled",
          "notifications",
          "profile_sidebar_border_color",
          "location",
          "screen_name",
          "verified",
          "time_zone",
          "profile_background_color",
          "profile_use_background_image",
          "protected",
          "name",
          "profile_text_color",
          "followers_count",
          "id",
          "id_str",
          "lang",
          "statuses_count",
          "follow_request_sent",
          "utc_offset",
          "listed_count",
          "is_translator",
          "show_all_inline_media"
        };

    url = "http://api.twitter.com/1.1/users/show/yusukey.json";
    User user = new UserJSONImpl(validateJSONObjectSchema(url, schema));
  }