user5603796
user5603796

Reputation: 389

Using a Tumblr API in Ruby

I am using tumblr_client gem to access Tumblr API.

I want to search all users posts containing a certain tag, not search a certain users posts containing a certain tag. I do not see documentation within the tumblr_client gem to be able to do this so I guessed the code and left the user link blank.

#!/usr/bin/ruby

require 'cinch'
require 'tumblr_client'

client = Tumblr::Client.new({
  :consumer_key => '[redacted]',
  :consumer_secret => '[redacted]',
  :oauth_token => '[redacted]',
  :oauth_token_secret => '[redacted]'
})

# Make the request
client.info

p client.posts('', :tag => "pony", :type => "photo", :limit => 10)

This is the current code that I am using, expecting 10 photos of a pony, but instead it results in this error message.

{"status"=>404, "msg"=>"Not Found"}

Please assist?

Upvotes: 1

Views: 159

Answers (1)

Kristján
Kristján

Reputation: 18803

You can't use the posts endpoint for this. If you look at the code, it's generating a URL (via blog_path) that uses the blog name you must provide in the first argument:

def blog_path(blog_name, ext)
  "v2/blog/#{full_blog_name(blog_name)}/#{ext}"
end

If you don't include blog_name, the URL is v2/blog//posts, and now it's obvious why you get a 404.

You want to be using the tagged endpoint, like so:

client.tagged('cool_things')

Upvotes: 0

Related Questions