Reputation: 8069
There are ways to get Posts and other details using tags, from your Tumblr Blog, and Vice Versa as per Tumblr API V2
I want to get a list of all tags (unique tags) irrespective of blog posts
So If I have 10 posts tagged Technology
, Web
and 3 posts tagged JavaScript
, Web
- I want to query my blog in such a way that it gives me Technology
, Web
and JavaScript
Say for eg., an array - results.posts.tags = ["Technology", "Web", "JavaScript"]
or an Object, which I can dig in to find the tags
and then iterate in a loop.
Upvotes: 3
Views: 4616
Reputation: 1
I know this is a old post, but I thought it might be useful for some people as I've taken the time to make this into a javascript which returns all the unique tags as a javascript object.
https://github.com/scintillate/tumblrtag/
Upvotes: 0
Reputation: 1392
I've never used the Tumblr API, but it looks like you should be able to build a list of tags - but there is no built in method for it. First you'll have to find the total # of posts in the blog by querying the /info
method1. The URL for that is:
api.tumblr.com/v2/blog/{base-hostname}/info?api_key={key}
Taking the response from that and decoding it into an object (jQuery, extjs, w/e will work) you can find the posts
field for the total # of posts. Using that you can start to pull back the posts 20 at a time, the max according to the API, using the /posts
method. The URL for that is:
api.tumblr.com/v2/blog/{base-hostname}/posts[/type]?api_key={key}&[optional-params=]
You probably want to omit /type
, but you will need to specify offset
in the optional-params. With the offset you can just work through all the posts, 20 at a time2, until you have downloaded them all (the number you got from the /info
query). As you download the posts just keep track of which tags you get.
It's kind of unfortunate you have to download the body of the post just to get the tag list, but I don't see any other method that gives you the tags, or a option to supress the body and just see the meta-data for posts.
**EDIT**
1: Per Felix's comment the # of posts /info
returns is known to be slightly off sometimes. In the case where the expected number is high, you need to make sure you are only looping over results you actually received, not what you anticipated. To handle the case where the expected number is low, you could do one query past what the end should be and see if you get any results back. At that point though you might consider dropping the /info
query all together and just querying /posts
until you don't get any more results.
2: Per Felix's second comment, even though the API lists the range of values for how many posts you can pull down at once as 1-20
with 20
default, supposedly it will accept up to 50
. Pulling 50 results at a time could speed things up / lower your bandwidth, but it will make your code more complicated to do right. Since it is an undocumented feature (read: might just be a bug) there is no guarantee it will keep working. So you could try to query 50 at a time, but need to be prepared to handle a 400
error code, or something similar, in case they make their service match the API and then default back to 20.
Upvotes: 3
Reputation: 146
I know nothing of how it works, but it does: look at the Tumblr tag list bookmarklet. Should give you at least some code you can use.
Upvotes: 0