user2062024
user2062024

Reputation: 3661

Posting a video using Tumblr API in java

I am struggling with Tumblr api now. When I post a text only, it is pretty simple because I just need to provide a string title and a string body. Referring to the api doc ( http://www.tumblr.com/docs/en/api/v2#text-posts ), I used the following code and it worked successfully.

HttpPost hpost = new HttpPost(BASE_URL + "/blog/" + blog + ".tumblr.com/post");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("type", "text"));
nameValuePairs.add(new BasicNameValuePair("text", title));
nameValuePairs.add(new BasicNameValuePair("body", body));
hpost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
consumer.sign(hpost);
DefaultHttpClient client = new DefaultHttpClient();
HttpResponse resp = null;
resp = client.execute(hpost);

However, the problem is that when I post a video, I have to provide a string caption and an array player. ( http://www.tumblr.com/docs/en/api/v2#video-posts ) My question is, how can I pass an embed code to a NameValuePair object? I just need to post a single video so the array will be of size 1. I tried the following code:

HttpPost hpost = new HttpPost(BASE_URL + "/blog/" + blog + ".tumblr.com/post");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("type", "video"));
nameValuePairs.add(new BasicNameValuePair("caption", title));
nameValuePairs.add(new BasicNameValuePair("player", "<embed src='blah'>"));

but to no avail. If anyone can help with this, it will be really grateful. Thanks!

Upvotes: 0

Views: 832

Answers (1)

BrianPlummer
BrianPlummer

Reputation: 164

The values caption and and array player on are on the Response from querying a video plog post. Not the parameters for adding a new vide post. The section: tumblr.com/docs/en/api/v2#posting contains the parameters you want to use: caption,embed,data (all strings...)

Upvotes: 2

Related Questions