在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:ryanmcgrath/twython开源软件地址:https://github.com/ryanmcgrath/twython开源编程语言:Python 100.0%开源软件介绍:Twython
Note: As of Twython 3.7.0, there's a general call for maintainers put out. If you find the project useful and want to help out, reach out to Ryan with the info from the bottom of this README. Great open source project to get your feet wet with! Features
InstallationInstall Twython via pip: $ pip install twython If you're on a legacy project that needs Python 2.7 support, you can install the last version of Twython that supported 2.7:
Or, if you want the code that is currently on GitHub: git clone git://github.com/ryanmcgrath/twython.git
cd twython
python setup.py install DocumentationDocumentation is available at https://twython.readthedocs.io/en/latest/ Starting OutFirst, you'll want to head over to https://apps.twitter.com and register an application! After you register, grab your applications The most common type of authentication is Twitter user authentication using OAuth 1. If you're a web app planning to have users sign up with their Twitter account and interact with their timelines, updating their status, and stuff like that this is the authentication for you! First, you'll want to import Twython from twython import Twython Obtain Authorization URLNow, you'll want to create a Twython instance with your
APP_KEY = 'YOUR_APP_KEY'
APP_SECRET = 'YOUR_APP_SECRET'
twitter = Twython(APP_KEY, APP_SECRET)
auth = twitter.get_authentication_tokens(callback_url='http://mysite.com/callback') From the OAUTH_TOKEN = auth['oauth_token']
OAUTH_TOKEN_SECRET = auth['oauth_token_secret'] Send the user to the authentication url, you can obtain it by accessing auth['auth_url'] Handling the CallbackIf your application is a Desktop or Mobile Application oauth_verifier will be the PIN code After they authorize your application to access some of their account details, they'll be redirected to the callback url you specified in You'll want to extract the Django example: oauth_verifier = request.GET['oauth_verifier'] Now that you have the twitter = Twython(
APP_KEY, APP_SECRET,
OAUTH_TOKEN, OAUTH_TOKEN_SECRET
)
final_step = twitter.get_authorized_tokens(oauth_verifier) Once you have the final user tokens, store them in a database for later use:: OAUTH_TOKEN = final_step['oauth_token']
OAUTH_TOKEN_SECRET = final_step['oauth_token_secret'] For OAuth 2 (Application Only, read-only) authentication, see our documentation. Dynamic Function ArgumentsKeyword arguments to functions are mapped to the functions available for each endpoint in the Twitter API docs. Doing this allows us to be incredibly flexible in querying the Twitter API, so changes to the API aren't held up from you using them by this library. Basic UsageFunction definitions (i.e. get_home_timeline()) can be found by reading over twython/endpoints.py 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) Authenticated Users Home Timelinetwitter.get_home_timeline() Updating StatusThis method makes use of dynamic arguments, read more about them. twitter.update_status(status='See how easy using Twython is!') Advanced UsageQuestions, Comments, etc?My hope is that Twython is so simple that you'd never have to ask any questions, but if you feel the need to contact me for this (or other) reasons, you can hit me up at [email protected]. Or if I'm to busy to answer, feel free to ping [email protected] as well. Follow us on Twitter: Want to help?Twython is useful, but ultimately only as useful as the people using it (say that ten times fast!). If you'd like to help, write example code, contribute patches, document things on the wiki, tweet about it. Your help is always appreciated! |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论