【问题标题】:Ruby: How to pass options to user_timeline method of twitter gem?Ruby:如何将选项传递给 twitter gem 的 user_timeline 方法?
【发布时间】:2016-07-16 12:52:03
【问题描述】:

我正在使用sferik gem 获取推文。

我想将以下额外参数传递给方法“user_timeline”:

count、include_rts 和 exclude_replies

是否可以将这些作为参数传递?

如果是,我如何将这些额外参数传递给“user_timeline”方法并根据这些额外参数获取适当的响应?

感谢您的帮助!

【问题讨论】:

    标签: ruby-on-rails ruby twitter twitter-gem


    【解决方案1】:

    查看文档here。您应该能够像这样传递支持的选项:

    user_timeline(your_user, {
     :include_rts => true,
     :exclude_replies => true,
     :count => 42 
    })
    

    更新 正如@mudasobwa 在评论中正确指出的那样,如果您使用的是ruby 1.9+,则可以使用以下更简单的语法:

    user_timeline(your_user, include_rts: true, exclude_replies: true, count: 42)
    

    【讨论】:

    • 在 Ruby 1.9 中,大括号和 hashrocket 语法有点过时了:user_timeline(your_user, include_rts: true, exclude_replies: true, count: 42)
    • 绝对!只是为了安全起见,因为 OP 从未提及该版本。
    • 谢谢@Shaunak 和@mudasobwa!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-13
    • 2013-11-27
    • 1970-01-01
    相关资源
    最近更新 更多