[英]Uploading multiple images on twitter using Ruby on Rails Twitter Gem
What should be the format for the parameter: media
, in the call below, for updating with multiple images. 参数的格式应该是什么:在下面的调用中,
media
用来更新多个图像。
def twitter_status_update_with_media (twitter_client, text, media, opts)
twitter_client.update_with_media(self.text, media, opts)
end
For a single image, File.new(filepath)
works fine.. 对于单个图像,
File.new(filepath)
可以正常工作。
To attach multiple images to a tweet, you first need to upload the images using the upload
method: 要将多个图像附加到一条推文,您首先需要使用上
upload
方法上载这些图像:
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)
This will return media IDs, which you can pass into the media_ids
parameter (as a comma-separated string) of the update
method. 这将返回媒体ID,您可以将其传递到
update
方法的media_ids
参数(以逗号分隔的字符串)中。
twitter_client.update("Tweet text", :media_ids => media_ids.join(','))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.