Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Feature request : Add media to tweet #18

Closed
sdh100shaun opened this issue Mar 16, 2014 · 5 comments
Closed

Feature request : Add media to tweet #18

sdh100shaun opened this issue Mar 16, 2014 · 5 comments

Comments

@sdh100shaun
Copy link

can we add media to tweets ? I think looking at the code this would only be achievable by changing the update method to use the client client.update_with_media method or preferably add another method around that

@muffinista
Copy link
Owner

Hey, I'd probably accept a pull request with that, but I'm not sure how to go about it and keep things clean. That said, since you can access the client instance directly, it should possible to do media tweets now with something like this:

#
# ... assorted chatterbot code ...
#
replies do |tweet|
  client.update_with_media "hello!", File.open(path_to_image), in_reply_to_status_id:tweet.id
end

That's untested, but it or something like it should work.

@sdh100shaun
Copy link
Author

thanks, I have for the time being gone down the access the client directly route - will fork and thing about a clean way to go about the addition of media

@zackphilipps
Copy link

Hey guys! I tried accessing the client directly and received the following error even though my app has read and write permissions... Any ideas?

/Library/Ruby/Gems/2.0.0/gems/twitter-5.16.0/lib/twitter/rest/response/raise_error.rb:15:in 'on_complete': Read-only application cannot POST. (Twitter::Error::Unauthorized)

    from /Library/Ruby/Gems/2.0.0/gems/faraday-0.9.2/lib/faraday/response.rb:9:in `block in call'
    from /Library/Ruby/Gems/2.0.0/gems/faraday-0.9.2/lib/faraday/response.rb:57:in `on_complete'
    from /Library/Ruby/Gems/2.0.0/gems/faraday-0.9.2/lib/faraday/response.rb:8:in `call'
    from /Library/Ruby/Gems/2.0.0/gems/faraday-0.9.2/lib/faraday/request/url_encoded.rb:15:in `call'
    from /Library/Ruby/Gems/2.0.0/gems/faraday-0.9.2/lib/faraday/request/multipart.rb:14:in `call'
    from /Library/Ruby/Gems/2.0.0/gems/twitter-5.16.0/lib/twitter/rest/request/multipart_with_file.rb:19:in `call'
    from /Library/Ruby/Gems/2.0.0/gems/faraday-0.9.2/lib/faraday/rack_builder.rb:139:in `build_response'
    from /Library/Ruby/Gems/2.0.0/gems/faraday-0.9.2/lib/faraday/connection.rb:377:in `run_request'
    from /Library/Ruby/Gems/2.0.0/gems/faraday-0.9.2/lib/faraday/connection.rb:177:in `post'
    from /Library/Ruby/Gems/2.0.0/gems/twitter-5.16.0/lib/twitter/rest/request.rb:33:in `perform'
    from /Library/Ruby/Gems/2.0.0/gems/twitter-5.16.0/lib/twitter/rest/utils.rb:50:in `perform_request'
    from /Library/Ruby/Gems/2.0.0/gems/twitter-5.16.0/lib/twitter/rest/utils.rb:72:in `perform_request_with_object'
    from /Library/Ruby/Gems/2.0.0/gems/twitter-5.16.0/lib/twitter/rest/utils.rb:64:in `perform_post_with_object'
    from /Library/Ruby/Gems/2.0.0/gems/twitter-5.16.0/lib/twitter/rest/tweets.rb:233:in `update_with_media'
    from ./boop_almbot.rb:112:in `block in <main>'
    from /Library/Ruby/Gems/2.0.0/gems/chatterbot-2.0.2/lib/chatterbot/handler.rb:26:in `call'
    from /Library/Ruby/Gems/2.0.0/gems/chatterbot-2.0.2/lib/chatterbot/handler.rb:26:in `call'
    from /Library/Ruby/Gems/2.0.0/gems/chatterbot-2.0.2/lib/chatterbot/streaming.rb:29:in `handle_streaming_object'
    from /Library/Ruby/Gems/2.0.0/gems/chatterbot-2.0.2/lib/chatterbot/bot.rb:90:in `block in stream!'
    from /Library/Ruby/Gems/2.0.0/gems/twitter-5.16.0/lib/twitter/streaming/client.rb:116:in `block in request'
    from /Library/Ruby/Gems/2.0.0/gems/twitter-5.16.0/lib/twitter/streaming/response.rb:27:in `call'
    from /Library/Ruby/Gems/2.0.0/gems/twitter-5.16.0/lib/twitter/streaming/response.rb:27:in `block in on_body'
    from /Library/Ruby/Gems/2.0.0/gems/twitter-5.16.0/lib/twitter/streaming/response.rb:25:in `each'
    from /Library/Ruby/Gems/2.0.0/gems/twitter-5.16.0/lib/twitter/streaming/response.rb:25:in `on_body'
    from /Library/Ruby/Gems/2.0.0/gems/twitter-5.16.0/lib/twitter/streaming/response.rb:16:in `<<'
    from /Library/Ruby/Gems/2.0.0/gems/twitter-5.16.0/lib/twitter/streaming/response.rb:16:in `<<'
    from /Library/Ruby/Gems/2.0.0/gems/twitter-5.16.0/lib/twitter/streaming/connection.rb:22:in `stream'
    from /Library/Ruby/Gems/2.0.0/gems/twitter-5.16.0/lib/twitter/streaming/client.rb:119:in `request'
    from /Library/Ruby/Gems/2.0.0/gems/twitter-5.16.0/lib/twitter/streaming/client.rb:37:in `filter'
    from /Library/Ruby/Gems/2.0.0/gems/chatterbot-2.0.2/lib/chatterbot/bot.rb:89:in `stream!'
    from /Library/Ruby/Gems/2.0.0/gems/chatterbot-2.0.2/lib/chatterbot/bot.rb:63:in `run_or_stream'
    from /Library/Ruby/Gems/2.0.0/gems/chatterbot-2.0.2/lib/chatterbot/bot.rb:49:in `block in initialize'

@muffinista
Copy link
Owner

That probably means that when you registered with Twitter, you setup an application to be read-only. You'll need to update those settings with Twitter, and maybe re-authenticate.

@zackphilipps
Copy link

Yeah I figured it out. It was initially set up as read/write but I had to escalate to DM privileges and re-authenticate anyway. Weird. Thanks for responding, and thanks for the tool!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants