English 中文(简体)
Twitter4j,“查询中指定的词汇太多”
原标题:Twitter4j, "Too many terms specified in query"

正在使用以下方法获取所有跟踪验证用户的用户的屏幕名 。

private void getFollowing() {   
     Twitter t = new TwitterFactory().getInstance();
     t.setOAuthConsumer(OAUTH.CONSUMER_KEY, OAUTH.CONSUMER_SECRET);
     aToken = getToken();
     t.setOAuthAccessToken(aToken);
     try {
        long[] friendsID = t.getFriendsIDs(userID, -1).getIDs();
        ResponseList<User> userName = t.lookupUsers(friendsID);
        int count = 0;
        for (User u : userName) {
            count++;
            Log.d("USERNAME : "+ Integer.toString(count), u.getScreenName());
        }
     } catch (TwitterException e) {
        e.printStackTrace();
    }
}

t. lookupUsers(friendsID) 导致以下错误。

W/System.err(16076) : {"errors" : [{"code": 18"Message": "查询中指定的太多术语"}\\\ /code>

从我的理解来看, LookupUsers () 方法将一次返回最多100个用户的信息。 我提供的可能不止此。 这会不会是原因? 如果是这样, 我如何限制原始请求, 并环绕其余用户获取全部屏幕名?

如果我搞错了为什么我搞错了 我还能做错什么?

<强 > ANSWER

    private void getFollowing() {   
         Twitter t = new TwitterFactory().getInstance();
         t.setOAuthConsumer(OAUTH.CONSUMER_KEY, OAUTH.CONSUMER_SECRET);
         aToken = getToken();
         t.setOAuthAccessToken(aToken);
         ArrayList<String> names = new ArrayList<String>();
         try {
            int start = 0;
            int finish = 100;
            ArrayList<Long> IDS = new ArrayList<Long>();
            long[] friendsID =  t.getFriendsIDs(userID, -1).getIDs();
            boolean check = true;
            while (check) {
                for (int i=start;i<finish;i++) {
//get first 100     
                    IDS.add(friendsID[i]);
//if at the end, stop
                    if (friendsID.length-1 == i) {
                        check = false;
                        break;                      
                    }
                }
//set values for next 100
                start = start+100;
                finish = finish+100;
                long[] ids = Longs.toArray(IDS);
                ResponseList<User> userName = t.lookupUsers(ids);
//clear so long[] holds max 100 at any given time
                IDS.clear();
                for (User u : userName) {
                    names.add(u.getScreenName());
                }
            }
            String[] screenNames = (String[]) names.toArray(new String[names.size()]);

            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, screenNames);
            mPreview.setAdapter(adapter);
         } catch (TwitterException e) {
            e.printStackTrace();
        }
    }
最佳回答
private void getFollowing() {   
     Twitter t = new TwitterFactory().getInstance();
     t.setOAuthConsumer(OAUTH.CONSUMER_KEY, OAUTH.CONSUMER_SECRET);
     aToken = getToken();
     t.setOAuthAccessToken(aToken);
     ArrayList<String> names = new ArrayList<String>();
     try {
        int start = 0;
        int finish = 100;
        ArrayList<Long> IDS = new ArrayList<Long>();
        long[] friendsID =  t.getFriendsIDs(userID, -1).getIDs();
        boolean check = true;
        while (check) {
            for (int i=start;i<finish;i++) {
                //get first 100     
                IDS.add(friendsID[i]);
                //if at the end, stop
                if (friendsID.length-1 == i) {
                    check = false;
                    break;                      
                }
            }
            //set values for next 100
            start = start+100;
            finish = finish+100;
            long[] ids = Longs.toArray(IDS);
            ResponseList<User> userName = t.lookupUsers(ids);
            //clear so long[] holds max 100 at any given time
            IDS.clear();
            for (User u : userName) {
                names.add(u.getScreenName());
            }
        }
        String[] screenNames = (String[]) names.toArray(new String[names.size()]);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, screenNames);
        mPreview.setAdapter(adapter);
     } catch (TwitterException e) {
        e.printStackTrace();
    }
}
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...