Reputation: 1286
I am doing a java application that uploads a video to twitvid and gets back the link of the video and post that to twitter.But I cant find any good example of uploading video to twitvid. The documentation at http://twitvid.pbworks.com/w/page/22556295/FrontPage is also confusing and no examples are given. Can anybody share an example or good documentation on this? The libraries are here at http://twitvid.pbworks.com/w/page/22556292/Client%20Libraries
Upvotes: 1
Views: 558
Reputation: 14709
Try this: Obviously, you'll need to import the necessary libraries, if you're using eclipse, it'll tell you what you need to import.
URL url = new URL("http://im.twitvid.com/api/uploadAndPost");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/xml");
OutputStream os = connection.getOutputStream();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
FileReader fileReader = new FileReader("filename.xml");
StreamSource source = new StreamSource(fileReader);
StreamResult result = new StreamResult(os);
transformer.transform(source, result);
os.flush();
connection.getResponseCode();
connection.disconnect();
Where filename.xml will look something like this (from http://twitvid.pbworks.com/w/page/22556308/Twitvid%20API%20Method%3A%20uploadandpost):
<?xml version='1.0' encoding='UTF-8'?>
<rsp status='ok'>
<status_id>1111</status_id>
<user_id>TwitUsername</user_id>
<media_id>3GS34</media_id>
<media_url>http://twitvid.com/3GS34</media_url>
<message>This is my tweet!</message>
<geo_latitude>57.64911</geo_latitude>
<geo_longitude>10.40744</geo_longitude>
</rsp>
Where you'd need to replace the values in the .xml with the values that are relevant to you. The twitvid page that I linked describes what should go in all the fields above. Good luck, hope that helps.
Edit: a lot of those fields are optional, for example, you probably don't need geo_latitude/longitude. That page should explain everything. I know it may seem confusing, but try to work with it. Hopefully the code above will solve your problems.
Upvotes: 1