Permalink
Browse files

Fulfill the API promise: IDs and screen names are accepted for lookup

The [Twitter API docs][1] state that we can lookup with either IDs or
screen names. The API now supports this in a convenient wrapper call.

  [1]: https://dev.twitter.com/docs/api/1/get/users/lookup
  • Loading branch information...
1 parent 3ef6f08 commit 4dd09c3e40e499e2c2b743db70afe6ee6cd34304 @francois committed Apr 19, 2012
View
11 twitter4j-core/src/main/java/twitter4j/TwitterImpl.java
@@ -498,6 +498,17 @@ public User showUser(long userId) throws TwitterException {
/**
* {@inheritDoc}
*/
+ public ResponseList<User> lookupUsers(long[] ids, String[] screenNames) throws TwitterException {
+ return factory.createUserList(get(conf.getRestBaseURL() +
+ "users/lookup.json", new HttpParameter[]{
+ new HttpParameter("screen_name", z_T4JInternalStringUtil.join(screenNames))
+ , new HttpParameter("user_id", z_T4JInternalStringUtil.join(screenNames))
+ , INCLUDE_ENTITIES}));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public ResponseList<User> lookupUsers(String[] screenNames) throws TwitterException {
return factory.createUserList(get(conf.getRestBaseURL() +
"users/lookup.json", new HttpParameter[]{
View
17 twitter4j-core/src/main/java/twitter4j/api/UserMethods.java
@@ -54,6 +54,19 @@
* Return up to 100 users worth of extended information, specified by either ID, screen name, or combination of the two. The author's most recent status (if the authenticating user has permission) will be returned inline.
* <br>This method calls http://api.twitter.com/1/users/lookup.json
*
+ * @param ids Specifies the ids of the users to return.
+ * @param screenNames Specifies the screen names of the users to return.
+ * @return users
+ * @throws TwitterException when Twitter service or network is unavailable
+ * @see <a href="https://dev.twitter.com/docs/api/1/get/users/lookup">GET users/lookup | Twitter Developers</a>
+ * @since Twitter4J 2.1.1
+ */
+ ResponseList<User> lookupUsers(long[] ids, String[] screenNames) throws TwitterException;
+
+ /**
+ * Return up to 100 users worth of extended information, specified by screen name. The author's most recent status (if the authenticating user has permission) will be returned inline.
+ * <br>This method calls http://api.twitter.com/1/users/lookup.json
+ *
* @param screenNames Specifies the screen names of the users to return.
* @return users
* @throws TwitterException when Twitter service or network is unavailable
@@ -63,10 +76,10 @@
ResponseList<User> lookupUsers(String[] screenNames) throws TwitterException;
/**
- * Return up to 100 users worth of extended information, specified by either ID, screen name, or combination of the two. The author's most recent status (if the authenticating user has permission) will be returned inline.
+ * Return up to 100 users worth of extended information, specified by ID. The author's most recent status (if the authenticating user has permission) will be returned inline.
* <br>This method calls http://api.twitter.com/1/users/lookup.json
*
- * @param ids Specifies the screen names of the users to return.
+ * @param ids Specifies the ids of the users to return.
* @return users
* @throws TwitterException when Twitter service or network is unavailable
* @see <a href="https://dev.twitter.com/docs/api/1/get/users/lookup">GET users/lookup | Twitter Developers</a>
View
5 twitter4j-core/src/test/java/twitter4j/UserMethodsTest.java
@@ -107,6 +107,11 @@ public void testLookupUsers() throws TwitterException {
assertNotNull(DataObjectFactory.getRawJSON(users.get(0)));
assertEquals(users.get(0), DataObjectFactory.createUser(DataObjectFactory.getRawJSON(users.get(0))));
assertNotNull(DataObjectFactory.getRawJSON(users));
+
+ users = twitter1.lookupUsers(new long[]{id1.id}, new String[]{id2.screenName});
+ assertEquals(2, users.size());
+ assertContains(users, id1);
+ assertContains(users, id2);
}
private void assertContains(ResponseList<User> users, TestUserInfo user) {

0 comments on commit 4dd09c3

Please sign in to comment.