加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 使用Ruby on Rails Twitter Gem在twitter上上

发布时间:2020-12-17 02:54:33 所属栏目:百科 来源:网络整理
导读:参数的格式应该是什么:媒体,在下面的调用中,用于更新多个图像. def twitter_status_update_with_media (twitter_client,text,media,opts) twitter_client.update_with_media(self.text,opts)end 对于单个图像,File.new(filepath)工作正常.. 解决方法 要将多
参数的格式应该是什么:媒体,在下面的调用中,用于更新多个图像.

def twitter_status_update_with_media (twitter_client,text,media,opts)
    twitter_client.update_with_media(self.text,opts)
end

对于单个图像,File.new(filepath)工作正常..

解决方法

要将多个图像附加到推文,首先需要使用上传方法上传图像:

media_ids = %w(image1.png image2.png image3.png image4.png).map do |filename|
  Thread.new do
    twitter_client.upload(File.new(filename))
  end
end.map(&:value)

这将返回媒体ID,您可以将其传递到update方法的media_ids参数(以逗号分隔的字符串形式).

twitter_client.update("Tweet text",:media_ids => media_ids.join(','))

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读