我正在将twitter整合到我的应用中,但登录功能无效。我在运行应用程序时出现以下错误。我使用的是twitter4j 3.0.5 lib。
以下是错误日志:
02-18 12:07:34.840: W/System.err(31448): No authentication challenges found
02-18 12:07:34.840: W/System.err(31448): Relevant discussions can be found on the Internet
at:
02-18 12:07:34.840: W/System.err(31448): http://www.google.co.jp/search?q=10f5ada3 or
02-18 12:07:34.840: W/System.err(31448): http://www.google.co.jp/search?q=0276a2ba
02-18 12:07:34.840: W/System.err(31448): TwitterException{exceptionCode=[10f5ada3-0276a2ba b8c63e52-4c5db04c], statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=3.0.5}
02-18 12:07:34.840: W/System.err(31448): at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:177)
02-18 12:07:34.840: W/System.err(31448): at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
02-18 12:07:34.840: W/System.err(31448): at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:98)
02-18 12:07:34.840: W/System.err(31448): at twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:122)
02-18 12:07:34.840: W/System.err(31448): at twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:104)
02-18 12:07:34.840: W/System.err(31448): at twitter4j.TwitterBaseImpl.getOAuthRequestToken(TwitterBaseImpl.java:298)
02-18 12:07:34.840: W/System.err(31448): at com.androidhive.twitterconnect.MainActivity$4.run(MainActivity.java:299)
02-18 12:07:34.840: W/System.err(31448): at java.lang.Thread.run(Thread.java:841)
02-18 12:07:34.840: W/System.err(31448): Caused by: java.io.IOException: No authentication challenges found
02-18 12:07:34.840: W/System.err(31448): at libcore.net.http.HttpURLConnectionImpl.getAuthorizationCredentials(HttpURLConnectionImpl.java:438)
02-18 12:07:34.840: W/System.err(31448): at libcore.net.http.HttpURLConnectionImpl.processAuthHeader(HttpURLConnectionImpl.java:418)
02-18 12:07:34.840: W/System.err(31448): at libcore.net.http.HttpURLConnectionImpl.processResponseHeaders(HttpURLConnectionImpl.java:367)
02-18 12:07:34.840: W/System.err(31448): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:301)
02-18 12:07:34.840: W/System.err(31448): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:497)
02-18 12:07:34.840: W/System.err(31448): at libcore.net.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:134)
02-18 12:07:34.840: W/System.err(31448): at twitter4j.internal.http.HttpResponseImpl.<init>(HttpResponseImpl.java:34)
02-18 12:07:34.840: W/System.err(31448): at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:141)
02-18 12:07:34.840: W/System.err(31448): ... 7 more
Error Code
/ ** *登录twitter的功能 * * /
private void loginToTwitter() {
// Check if already logged in
if (!isTwitterLoggedInAlready()) {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
Configuration configuration = builder.build();
TwitterFactory factory = new TwitterFactory(configuration);
twitter = factory.getInstance();
Thread th = new Thread(new Runnable() {
@Override
public void run() {
try {
//我在这里收到上述错误
requestToken = twitter
.getOAuthRequestToken(TWITTER_CALLBACK_URL);
MainActivity.this.startActivity(new Intent(
Intent.ACTION_VIEW, Uri.parse(requestToken
.getAuthenticationURL())));
} catch (TwitterException e) {
e.printStackTrace();
}
}
});
th.start();
} else {
// user already logged into twitter
Toast.makeText(getApplicationContext(),
"Already Logged into twitter", Toast.LENGTH_LONG).show();
}
}