I'm trying to add tags to a tumblr post with jquery, via the tumblr api.
So far I've called the api as so:
$.ajax({
url: 'http://api.tumblr.com/v2/blog/<My Blog>.tumblr.com/post/edit',
method: 'post',
data : ({
api_key :'<My Secret Key>',
}),
dataType: 'jsonp',
success: function(results){
}
})
I've found the location of the tags via get. They're located at
results.response.posts[#].tags[#]
I've never done an api post before though so I'm not sure what to do at the success function. Any help would be appreciated.
You're right you do need to use OAuth to make the request, however there are Javascript Clients (including one for jQuery) which will help you to do this.
Before proceeding though you will need to register your application in order to get the OAuth keys.
The jQuery specific OAuth client can be found here and the function below is adapted from it's documentation.
Information on the other Javascript clients can be found at the OAuth page.
function tagEdit(tagID, tags){
var oauth = OAuth({
consumer: {
public: '[public key]',
secret: '[secret key]'
},
signature_method: 'HMAC-SHA1'
});
var request_data = {
url: 'http://api.tumblr.com/v2/blog/[your blog].tumblr.com/post/edit',
method: 'POST',
data: {
id: tagID, tag: tags
}
};
var token = {
public: '[public token]',
secret: '[public key]'
};
$.ajax({
url: request_data.url,
type: request_data.method,
data: request_data.data,
headers: oauth.toHeader(oauth.authorize(request_data, token))
}).done(function(data) {
//what happens after the post has taken place
});
}
NB none of this has been tested as I don't have a tumblr account and I don't fancy registering for OAuth keys. Hope this might be of some use to you though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With