你可以尝试这样的事情:
String accesst = "ACCESS_TOKEN";
String accessts = "TOKEN_SECRET";
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthAccessToken(accesst);
builder.setOAuthAccessTokenSecret(accessts);
builder.setOAuthConsumerKey("CLIENT_ID");
builder.setOAuthConsumerSecret("CLIENT_SECRET");
OAuthAuthorization auth = new OAuthAuthorization(builder.build());
Twitter twitter_auth = new TwitterFactory().getInstance(auth);
String screenName = twitter_auth.getScreenName();
StatusUpdate status = new StatusUpdate("STATUS_TEXT");
status.setMedia(new File("YOUR_FILE_PATH"));// BY SPECIFYING FILE PATH
//status.setMedia("File name", new FileInputStream("")); // By InputStream
Status updateStatus = twitter_auth.updateStatus(status);
long id = updateStatus.getId(); // id of the status posted
从任何网址发布图片:
String img_url = "http://www.qualitywallpapers.net/w/media/original/2013/02/23/Twitter-bird-logo-PNG.png";
URL url1 = new URL(img_url);
BufferedImage image = ImageIO.read(url1);
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(image, "image/png", os);
InputStream is = new ByteArrayInputStream(os.toByteArray());
status.setMedia("hello", is);// By Stream