3
我想通過我的Android應用發佈推文。在互聯網上閱讀教程,我寫了下面提到的代碼。使用Twitter4J通過Android應用發佈推文
然而,我每次出現以下情況例外,要求twitter.updateStatus時():
TwitterException {exceptionCode = [,的StatusCode = -1,消息= NULL,代碼= -1,retryAfter = -1 ,rateLimitStatus = null,版本= 3.0.3}
以下事情已經嘗試過: a。閱讀此網站和其他網站上的最新帖子,瞭解代碼缺陷。 b。閱讀有關錯誤和建議的解決方案。 b。重建工作區。
任何輸入將是非常有幫助!提前致謝。
的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;
}
}