我想通过我的Android应用发布推文。在互联网上阅读教程,我写了下面提到的代码。
但是,每次调用twitter.updateStatus()时都会出现以下异常:
TwitterException {exceptionCode = [,statusCode = -1,message = null,code = -1,retryAfter = -1,rateLimitStatus = null,version = 3.0.3}
已经尝试过以下事项: 一个。阅读本网站和其他网站上的最新帖子,了解代码缺陷。 湾阅读有关错误和建议的解决方案。 湾重建工作区。
任何输入都将非常有用!提前谢谢。
的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.exampletweetdeep"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.exampletweetdeep.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java:
package com.example.exampletweetdeep;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.conf.ConfigurationBuilder;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity {
String consumerKey = "<<>>";
String consumerSecret = "<<>>";
String accessToken = "<<>>";
String accessSecret = "<<>>";
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i("Twitter activity", "First line");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i("Twitter activity", "Before building configuration");
ConfigurationBuilder confB = new ConfigurationBuilder();
confB.setDebugEnabled(true);
confB.setOAuthConsumerKey(consumerKey);
confB.setOAuthConsumerSecret(consumerSecret);
confB.setOAuthAccessToken(accessToken);
confB.setOAuthAccessTokenSecret(accessSecret);
Log.i("Twitter activity", "After building configuration");
TwitterFactory tF = new TwitterFactory(confB.build());
Twitter twitter = tF.getInstance();
try {
Status status = twitter.updateStatus("Testing from android");
Log.i("Twitter activity", "Done updating status");
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
答案 0 :(得分:0)
将twitter4j
库升级为twitter4j-core-3.0.5.jar
。我遇到了同样的问题,并通过升级库来解决它。