Hacker News new | past | comments | ask | show | jobs | submit login

Are there any command line twitter clients that allow the posting of images? ttytter can't do it, and it seems this "t" can't either.



Actually you can, see:

https://github.com/sferik/t/blob/7f1fcac61047dcb703e9519c837...

this is because the OP's own twitter ruby gem can do that, this CLI app is basically a front end for the ruby gem

    client.update_with_media("I'm tweeting with @gem!", File.new("/path/to/media.png"))
https://github.com/sferik/twitter/blob/48efb642beaa19355a4c1...


Well here's the essential bits in Python. I leave turning this into an actual CLI as an exercise for the interested reader.

    from requests_oauthlib import OAuth1Session
    import json


    keys = json.loads(open(keyfile).read())
    #  {"TWITTER_CONSUMER_KEY": "blah_blah_blah",
    #   "TWITTER_CONSUMER_SECRET": "blah_blah_blah",
    #   "TWITTER_ACCESS_TOKEN": "blah_blah_blah",
    #   "TWITTER_ACCESS_TOKEN_SECRET": "blah_blah_blah",}


    def twitter():
        return OAuth1Session(keys['TWITTER_CONSUMER_KEY'],
                             client_secret=keys['TWITTER_CONSUMER_SECRET'],
                             resource_owner_key=keys['TWITTER_ACCESS_TOKEN'],
                             resource_owner_secret=keys['TWITTER_ACCESS_TOKEN_SECRET'])


    def tweet(status, reply_to=None):
        endpoint = 'https://api.twitter.com/1.1/statuses/update.json'
        data = {'status': status}
        r = twitter().post(endpoint, data=data)
        return r.status_code


    def tweet_with_image(status, imgfile, reply_to=None):
        endpoint = 'https://api.twitter.com/1.1/statuses/update_with_media.json'
        data = {'status': status}
        if reply_to is not None:
            data.update({'in_reply_to_status_id': reply_to})
        r = twitter().post(endpoint, data=data, files={'media[]': open(imgfile, 'rb').read()})
        return r.status_code




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: