我正在开发一个 Android 应用程序来获取 Twitter 关注者。以下代码用于身份验证,我已成功登录。
consumer = new CommonsHttpOAuthConsumer(
key,
secret);
CommonsHttpOAuthProvider provider = new CommonsHttpOAuthProvider(
"http://twitter.com/oauth/request_token",
"http://twitter.com/oauth/access_token",
"http://twitter.com/oauth/authorize");
String authUrl = provider.retrieveRequestToken(consumer,
TWITTER_CALLBACK_URL);
Log.e("Twittwer ", "Please authorize this app!");
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(authUrl)));
为了获取关注者列表,我使用了下面的代码,但出现错误并附加了 logcat
AccessToken accessToken = new AccessToken(consumer.getToken(),
consumer.getTokenSecret());
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(key);
builder.setOAuthConsumerSecret(secret);
Configuration conf = builder.build();
twitter = new TwitterFactory(conf).getInstance();
twitter.setOAuthAccessToken(accessToken);
IDs followersId = twitter.getFollowersIDs(twitter.getId());
do {
for (long i : followersId.getIDs()) {
System.out.println("follower ID #" + i);
System.out.println(twitter.showUser(i).getName());
System.out.println(twitter.showUser(i)
.getProfileImageURL());
System.out.println(twitter.showUser(i).getURL());
}
} while (followersId.hasNext());
} catch (TwitterException e) {
System.out.println("e........"+e.getMessage());
e.printStackTrace();
}
日志猫:
02-18 16:13:10.632: W/System.err(734): Received authentication challenge is null 02-18 16:13:10.682: W/System.err(734): Relevant discussions can be found on the Internet at: 02-18 16:13:10.682: W/System.err(734): http://www.google.co.jp/search?q=a1259409 or 02-18 16:13:10.702: W/System.err(734): http://www.google.co.jp/search?q=06b97274 02-18 16:13:10.712: W/System.err(734): TwitterException{exceptionCode=[a1259409-06b97274 2e9324ac-d074d7d2], statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=3.0.3} 02-18 16:13:10.752: W/System.err(734): at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:192) 02-18 16:13:10.903: W/System.err(734): at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61) 02-18 16:13:11.012: W/System.err(734): at twitter4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:89) 02-18 16:13:11.062: W/System.err(734): at twitter4j.TwitterBaseImpl.fillInIDAndScreenName(TwitterBaseImpl.java:126) 02-18 16:13:11.123: W/System.err(734): at twitter4j.TwitterBaseImpl.getId(TwitterBaseImpl.java:118) 02-18 16:13:11.142: W/System.err(734): at com.nest.twitterfriendsfinder.MainActivity$getFollowers.doInBackground(MainActivity.java:276) 02-18 16:13:11.152: W/System.err(734): at com.nest.twitterfriendsfinder.MainActivity$getFollowers.doInBackground(MainActivity.java:1) 02-18 16:13:11.192: W/System.err(734): at android.os.AsyncTask$2.call(AsyncTask.java:264) 02-18 16:13:11.212: W/System.err(734): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 02-18 16:13:11.232: W/System.err(734): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 02-18 16:13:11.302: W/System.err(734): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208) 02-18 16:13:11.362: W/System.err(734): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 02-18 16:13:11.362: W/System.err(734): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 02-18 16:13:11.362: W/System.err(734): at java.lang.Thread.run(Thread.java:856) 02-18 16:13:11.362: W/System.err(734): Caused by: java.io.IOException: Received authentication challenge is null 02-18 16:13:11.372: W/System.err(734): at libcore.net.http.HttpURLConnectionImpl.processAuthHeader(HttpURLConnectionImpl.java:397) 02-18 16:13:11.372: W/System.err(734): at libcore.net.http.HttpURLConnectionImpl.processResponseHeaders(HttpURLConnectionImpl.java:345) 02-18 16:13:11.372: W/System.err(734): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:276) 02-18 16:13:11.372: W/System.err(734): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:479) 02-18 16:13:11.372: W/System.err(734): at twitter4j.internal.http.HttpResponseImpl.<init>(HttpResponseImpl.java:34) 02-18 16:13:11.382: W/System.err(734): at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:156)
这段代码有什么问题。我在一些帖子中读到检查模拟器中的时间戳。但是模拟器中的时间和日期是正确的。请给我一些帮助。提前谢谢..
[编辑] 我 这对吗?