twitter - Tweeting Images Programatically -


i have business requirement project i'm working on allow users print, email , share image on facebook , twitter. first 3 simple whereas i'm finding impossible find succinct example of how post tweet image using client side scripting. i've seen various solutions using twitter api , of them php based. surely can't difficult.

any appreciated.

this example uses twitterapi python library.

from twitterapi import twitterapi  tweet_text = 'some tweet text' image_path = './some_image.png'  consumer_key = '' consumer_secret = '' access_token_key = '' access_token_secret = ''  api = twitterapi(consumer_key,consumer_secret,access_token_key,access_token_secret)  # step 1 - upload image file = open(image_path, 'rb') data = file.read() r = api.request('media/upload', none, {'media': data}) print('upload media success' if r.status_code == 200 else 'upload media failure')  # step 2 - post tweet reference uploaded image if r.status_code == 200:     media_id = r.json()['media_id']     r = api.request('statuses/update', {'status': tweet_text, 'media_ids': media_id})     print('update status success' if r.status_code == 200 else 'update status failure') 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -