2013-07-01 67 views
0

你好,我正在twitter API twitter4j工作。我想通過我的Java代碼來發送Twitt在我的Twitter賬戶,但是當我嘗試編譯它,我得到了一些錯誤,我不明白 我的Java代碼Twitter與Java代碼整合的錯誤?

public class entry { 
    public static void main(String ar[])throws TwitterException, IOException 
    { 
     ConfigurationBuilder cb = new ConfigurationBuilder(); 
     cb.setDebugEnabled(true); 
     cb.setOAuthConsumerKey("dJGC64ozxFNfs7D3LK07oA"); 
     cb.setOAuthConsumerSecret("ExvnfE8AOM5vjqdjANoRdZyLKSOo2LZyHnxo2ERWzOs"); 
     cb .setOAuthAccessToken("*****************************"); 
     cb.setOAuthAccessTokenSecret("**************************"); 
     Twitter tf=new TwitterFactory(cb.build()).getInstance(); 
     tf.updateStatus("test ! "); 
    } 
} 

錯誤,我正在歌廳當我嘗試編譯我的代碼:

Exception in thread "main" A JSONObject text must begin with '{' found: 
at 2 [character 3 line 1] 
Relevant discussions can be found on the Internet at: 
    http://www.google.co.jp/search?q=6f994c35 or 
TwitterException{exceptionCode=[6f994c35-006e990b 1b2aeabf-9f2c6cb7], statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=3.0.3} 
    at twitter4j.internal.http.HttpResponse.asJSONObject(HttpResponse.java:153) 
    at twitter4j.internal.json.StatusJSONImpl.<init>(StatusJSONImpl.java:66) 
    at twitter4j.internal.json.z_T4JInternalJSONImplFactory.createStatus(z_T4JInternalJSONImplFactory.java:69) 
    at twitter4j.TwitterImpl.updateStatus(TwitterImpl.java:241) 
    at twiterapplication.entry.main(entry.java:29) 
Caused by: twitter4j.internal.org.json.JSONException: A JSONObject text must begin with '{' found: 
http://www.google.co.jp/search?q=006e990b 
+0

這是'entry.java'的第29行嗎? (提示:類名應以「Entry」的大寫字母開頭。) – 2013-07-01 12:46:45

+0

第29行的代碼tf.updateStatus(「test!」); – Simmant

+0

有沒有解決方案先生 – Simmant

回答

0

試試看this implementation

+0

非常感謝你對我的問題給予回答先生,但問題仍然是先生 – Simmant

+0

這裏是另一個線程,我發現可能會有所幫助。 https://groups.google.com/forum/#!topic/twitter4j/la9P0lPVyH4 –

+0

非常感謝先生,當我做了以下更改,然後1例外從上面被刪除,但仍有一個例外仍然是 相同 例外是: TwitterException {exceptionCode = [4adef3f6-00a4bea5 3ba5a640-6a6f93d1],statusCode = -1,message = null,code = -1,retryAfter = -1,rateLimitStatus = null,version = 3.0.3} – Simmant

0

好吧,非常感謝所有那些最終回答我的問題的人,我的代碼正在工作,現在我的twit已經顯示在我的ID上了。我做我的代碼,現在我的代碼工作正常

我的代碼只有以下一些簡單的變化是:

Twitter twitter= new TwitterFactory().getInstance(); 
twitter.setOAuthConsumer("************", "*************"); 
AccessToken newAccessToken = new AccessToken("******","*********"); 
System.out.println(newAccessToken); 
twitter.setOAuthAccessToken(newAccessToken); 
String s=twitter.getScreenName(); 
Status myStatus = twitter.updateStatus("Your message here"); 

此代碼工作正常,現在我打電話setOAuthConsumer與Twitter的對象,並創建的對象AccessToken並通過twitter對象將其對象傳遞給setOAuthAccessToken,並且我的代碼對於所有guyzz再次運行良好thanxx Marco Corona先生您的回答對我很有幫助。謝謝