Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用twitter4j的Twitter速率限制_Java_Twitter_Twitter4j - Fatal编程技术网

Java 使用twitter4j的Twitter速率限制

Java 使用twitter4j的Twitter速率限制,java,twitter,twitter4j,Java,Twitter,Twitter4j,在使用twitter4j库使用方法Twitter.getFollowersIDs时,我经常会遇到超出异常率限制的情况。在调用此方法之前,我会检查是否已超过速率限制,如下所示: if(Twitter.getRateLimitStatus().get("/followers/ids").getRemaining() > 0) 如果我尝试使用getRateLimitStatus/followers/ids方法,我会得到一个错误 {"errors":[{"code":32,"message":

在使用twitter4j库使用方法Twitter.getFollowersIDs时,我经常会遇到超出异常率限制的情况。在调用此方法之前,我会检查是否已超过速率限制,如下所示:

if(Twitter.getRateLimitStatus().get("/followers/ids").getRemaining() > 0) 
如果我尝试使用getRateLimitStatus/followers/ids方法,我会得到一个错误

{"errors":[{"code":32,"message":"Could not authenticate you."}]}

我做错了什么?

根据我的经验,这个错误可能是误导性的,因为GetLeving中的早期错误没有正确抛出。 我做这件事的方式是按照

    JSONObject jsonObject = new JSONObject(twitter.getRateLimitStatus().get("/followers/ids"));
    try {
        int remaining = Integer.parseInt(jsonObject.get("remaining").toString());
        if (remaining == 0)
        {
            int secondsUntilReset = Integer.parseInt(jsonObject.get("secondsUntilReset").toString());
            System.out.println("Waiting for seconds: ".concat(jsonObject.get("secondsUntilReset").toString()));
            Thread.sleep((( secondsUntilReset ) * 1000));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    } 

等等…

您是否设置了身份验证?见:见我的答案: