This section will cover how to use Twython and interact with some more advanced API calls
Before you make any API calls, make sure you authenticated the user (or app)!
Note
All sections on this page will assume youâre using a Twython instance
Create a Twython instance with your application keys and the users OAuth tokens
from twython import Twython twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)Posting a Status with an Editing Image¶
This example resizes an image, then uploads it as a media object and associates it with a status update.
# Assume you are working with a JPEG from PIL import Image try: # Python 3 from io import StringIO except ImportError: # Python 2 from StringIO import StringIO photo = Image.open('/path/to/file/image.jpg') basewidth = 320 wpercent = (basewidth / float(photo.size[0])) height = int((float(photo.size[1]) * float(wpercent))) photo = photo.resize((basewidth, height), Image.ANTIALIAS) image_io = StringIO.StringIO() photo.save(image_io, format='JPEG') # If you do not seek(0), the image will be at the end of the file and # unable to be read image_io.seek(0) response = twitter.upload_media(media=image_io) twitter.update_status(status='Checkout this cool image!', media_ids=[response['media_id']])Search Generator¶
So, if youâre pretty into Python, you probably know about generators
That being said, Twython offers a generator for search results and can be accessed by using the following code:
from twython import Twython twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) results = twitter.cursor(twitter.search, q='python') for result in results: print(result)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4