10

Twitterのステータスを正常に更新できるAndroidアプリがあります。画像を表示する Web ページへのリンクを共有するために使用しています。インスタグラムと同じように、ツイートと一緒に画像の縮小プレビューが表示されるといいと思います。ツイートと一緒にこの画像をアップロードするにはどうすればよいですか?

4

1 に答える 1

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を使用した最新の jar ファイルがあることを確認してください。

于 2012-10-05T06:07:00.097 に答える