Making Twitter Media Upload Api work with Java
I was trying to upload an image and do status update on twitter using there api version 1.1. For this I was using media/upload.json . I was trying to send content of files as base64 encoded string and setting the appropriate content-type and content-transfer-encoding. But this didn't work. I was getting errors like: 1) Missing paramter media 2) Could not authenticate. My main reason to use this approach was I was getting image url and didn't wanted to save it into a file. But this never worked, then I took a different approach of saving the imageurl into a file and doing a multi part upload. Code for it is below. Hope this helps someone. private String uploadImage(String imageUrl) { File f = new File("/tmp/twitterUploadImage_"+StringUtil.encodeURL(imageUrl)); try { FileUtils.copyURLToFile(new URL(imageUrl), f); } catch (IOException e) { logger.severe("Failed to save image in a file"); return null; } U