Java Twitter4j与用户的问题';s受保护的数据

Java Twitter4j与用户的问题';s受保护的数据,java,twitter,twitter4j,Java,Twitter,Twitter4j,我使用twitterjavaapi tweet4j从twitter用户检索数据。我有一个要从中检索数据的用户ID列表。我读了一个字符串ID列表,并试图通过TwitterJavaAPI将数据提取到我的数据库中。但是,有些用户对其数据有保护。因此,在某些ID中,我得到了身份验证错误。由于我的列表非常庞大,如何能够从没有身份验证权限的用户自动创建异常?twitter4j中是否有任何方法可供受保护或不受保护的用户使用 我得到的错误是: Exception in thread "main" 401:Aut

我使用twitterjavaapi tweet4j从twitter用户检索数据。我有一个要从中检索数据的用户ID列表。我读了一个字符串ID列表,并试图通过TwitterJavaAPI将数据提取到我的数据库中。但是,有些用户对其数据有保护。因此,在某些ID中,我得到了身份验证错误。由于我的列表非常庞大,如何能够从没有身份验证权限的用户自动创建异常?twitter4j中是否有任何方法可供受保护或不受保护的用户使用

我得到的错误是:

Exception in thread "main" 401:Authentication credentials 
(https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have 
set valid consumer key/secret, access token/secret, and the system clock is in sync.
[Wed Apr 30 15:35:18 EEST 2014]date: Wed, 30 Apr 2014 12:36:58 GMT
[Wed Apr 30 15:35:18 EEST 2014]x-transaction: 0d6f0c50c647c52e 
[Wed Apr 30 15:35:18 EEST 2014]pragma: no-cache
[Wed Apr 30 15:35:18 EEST 2014]cache-control: no-cache, no-store, must-revalidate, pre-
check=0, post-check=0
{"request":"\/1.1\/statuses\/user_timeline.json?
user_id=787323013&include_my_retweet=true&include_entities=true","error":"Not 
authorized."}

[Wed Apr 30 15:35:18 EEST 2014]x-content-type-options: nosniff
[Wed Apr 30 15:35:18 EEST 2014]x-xss-protection: 1; mode=block
[Wed Apr 30 15:35:18 EEST 2014]x-rate-limit-limit: 180
Relevant discussions can be found on the Internet at:
[Wed Apr 30 15:35:18 EEST 2014]expires: Tue, 31 Mar 1981 05:00:00 GMT
http://www.google.co.jp/search?q=0742d262 or
http://www.google.co.jp/search?q=32729de5
[Wed Apr 30 15:35:18 EEST 2014]set-cookie: guest_id=v1%3A139886141837883092;   
Domain=.twitter.com; Path=/; Expires=Fri, 29-Apr-2016 12:36:58 UTC
[Wed Apr 30 15:35:18 EEST 2014]set-cookie: lang=en
[Wed Apr 30 15:35:18 EEST 2014]www-authenticate: OAuth realm="https://api.twitter.com"
[Wed Apr 30 15:35:18 EEST 2014]content-length: 143
[Wed Apr 30 15:35:18 EEST 2014]x-rate-limit-reset: 1398862209
[Wed Apr 30 15:35:18 EEST 2014]server: tfe
[Wed Apr 30 15:35:18 EEST 2014]strict-transport-security: max-age=631138519
[Wed Apr 30 15:35:18 EEST 2014]x-access-level: read-write-directmessages
[Wed Apr 30 15:35:18 EEST 2014]{"request":"\/1.1\/statuses\/user_timeline.json?
user_id=787323013&include_my_retweet=true&include_entities=true","error":"Not
authorized."}



TwitterException{exceptionCode=[0742d262-32729de5], statusCode=401, message=null, 
code=-1, retryAfter=-1, rateLimitStatus=RateLimitStatusJSONImpl{remaining=114,
limit=180, resetTimeInSeconds=1398862209, secondsUntilReset=890}, version=4.0.1}
at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:164)
at twitter4j.HttpClientBase.request(HttpClientBase.java:53)
at twitter4j.HttpClientBase.get(HttpClientBase.java:71)
at twitter4j.TwitterImpl.get(TwitterImpl.java:1968)
at twitter4j.TwitterImpl.getUserTimeline(TwitterImpl.java:156)
at twitter4j.TwitterImpl.getUserTimeline(TwitterImpl.java:177)
at twitter4j.examples.tweets.UpdateStatus.main(UpdateStatus.java:116)

您应该捕获异常并继续处理,如下所示:

for (long userId : userIds) { // presumably you have a list of users 

    try {

        // call twitter4j here and process results

    }
    catch (TwitterException e) {
        // do not throw if user has protected tweets, or if they deleted their account
        if (e.getStatusCode() == HttpResponseCode.UNAUTHORIZED ||
            e.getStatusCode() == HttpResponseCode.NOT_FOUND) {

            // log something here
        }
        else {
            throw e;
        }
    }
}

您应该捕获异常并继续处理,如下所示:

for (long userId : userIds) { // presumably you have a list of users 

    try {

        // call twitter4j here and process results

    }
    catch (TwitterException e) {
        // do not throw if user has protected tweets, or if they deleted their account
        if (e.getStatusCode() == HttpResponseCode.UNAUTHORIZED ||
            e.getStatusCode() == HttpResponseCode.NOT_FOUND) {

            // log something here
        }
        else {
            throw e;
        }
    }
}

您得到了什么错误或异常?每次尝试都可以使用try…catch吗?我可以添加什么异常?您得到了什么错误或异常?每次尝试都可以使用try…catch吗?我可以添加什么异常?