【问题标题】:Using a Tumblr API in Ruby在 Ruby 中使用 Tumblr API
【发布时间】:2016-05-05 21:30:57
【问题描述】:

我正在使用tumblr_client gem 来访问 Tumblr API。

我想搜索包含某个标签的所有用户帖子,而不是搜索包含某个标签的某些用户帖子。我没有看到 tumblr_client gem 中的文档能够做到这一点,所以我猜到了代码并将用户链接留空。

#!/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)

这是我正在使用的当前代码,预计有 10 张小马的照片,但结果却导致了此错误消息。

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

请帮忙?

【问题讨论】:

    标签: ruby json api rubygems tumblr


    【解决方案1】:

    您不能为此使用posts 端点。如果您查看 the code,它会生成一个 URL(通过 blog_path),该 URL 使用您必须在第一个参数中提供的博客名称:

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

    如果您不包含 blog_name,则 URL 为 v2/blog//posts,现在很明显为什么会收到 404。

    您想使用tagged 端点,如下所示:

    client.tagged('cool_things')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 2014-02-16
      • 2011-06-08
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多