2012-09-30 50 views
10

我有一個Android應用程序,通過它我可以成功地更新Twitter狀態。我正在使用它來分享鏈接到顯示圖像的網頁。我認爲,與instagram一樣,以推文的形式縮小預覽效果併發布推文會很好。我如何將此圖片與我的推文一起上傳?Android的twitter4j上傳圖像

+0

嘗試最新的jar文件此更新的twitter4j罐子http://stackoverflow.com/questions/17093499/how圖像到推特的Android/20633178#20633178 – Prachi

回答

43

我有相同的要求,有時候回來,最後來的功能可能會幫助你。

/** 
* To upload a picture with some piece of text. 
* 
* 
* @param file The file which we want to share with our tweet 
* @param message Message to display with picture 
* @param twitter Instance of authorized Twitter class 
* @throws Exception exception if any 
*/ 

public void uploadPic(File file, String message,Twitter twitter) throws Exception { 
    try{ 
     StatusUpdate status = new StatusUpdate(message); 
     status.setMedia(file); 
     twitter.updateStatus(status);} 
    catch(TwitterException e){ 
     Log.d("TAG", "Pic Upload error" + e.getErrorMessage()); 
     throw e; 
    } 
} 

注:若要使用此,請確保你有我用twitter4j-core-2.2.5.jar這個

+5

不錯!非常感謝。完美工作! :) –

+0

@Akki你能幫我嗎 – Ishtiaq

+1

非常感謝。 – AB1209