Begin docs
[ci skip]
This commit is contained in:
parent
ec2bd7d686
commit
55641a1966
72 changed files with 26300 additions and 1 deletions
66
docs/_build/html/_sources/usage/basic_usage.txt
vendored
Normal file
66
docs/_build/html/_sources/usage/basic_usage.txt
vendored
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
.. _basic-usage:
|
||||
|
||||
Basic Usage
|
||||
===========
|
||||
|
||||
This section will cover how to use Twython and interact with some basic Twitter API calls
|
||||
|
||||
Before you make any API calls, make sure you :ref:`authenticated <starting-out>` the user!
|
||||
|
||||
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)
|
||||
|
||||
.. admonition:: Important
|
||||
|
||||
All sections on this page will assume you're using a Twython instance
|
||||
|
||||
What Twython Returns
|
||||
--------------------
|
||||
|
||||
Twython returns a dictionary of JSON response from Twitter
|
||||
|
||||
User Information
|
||||
----------------
|
||||
|
||||
Documentation: https://dev.twitter.com/docs/api/1.1/get/account/verify_credentials
|
||||
|
||||
::
|
||||
|
||||
twitter.verify_credentials()
|
||||
|
||||
Authenticated Users Home Timeline
|
||||
---------------------------------
|
||||
|
||||
Documentation: https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline
|
||||
|
||||
::
|
||||
|
||||
twitter.get_home_timeline()
|
||||
|
||||
Search
|
||||
------
|
||||
|
||||
Documentation: https://dev.twitter.com/docs/api/1.1/get/search/tweets
|
||||
|
||||
::
|
||||
|
||||
twitter.search(q='python')
|
||||
|
||||
To help explain :ref:`dynamic function arguments <starting-out>` a little more, you can see that the previous call used the keyword argument ``q``, that is because Twitter specifies in their `search documentation <https://dev.twitter.com/docs/api/1.1/get/search/tweets>`_ that the search call accepts the parameter "q". You can pass mutiple keyword arguments. The search documentation also specifies that the call accepts the parameter "result_type"
|
||||
|
||||
::
|
||||
|
||||
twitter.search(q='python', result_type='popular')
|
||||
|
||||
Updating Status
|
||||
---------------
|
||||
|
||||
Documentation: https://dev.twitter.com/docs/api/1/post/statuses/update
|
||||
|
||||
::
|
||||
|
||||
twitter.update_status(status='See how easy using Twython is!')
|
||||
|
||||
42
docs/_build/html/_sources/usage/install.txt
vendored
Normal file
42
docs/_build/html/_sources/usage/install.txt
vendored
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
.. _install:
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
Information on how to properly install Twython
|
||||
|
||||
|
||||
Pip or Easy Install
|
||||
-------------------
|
||||
|
||||
Install Twython via `pip <http://www.pip-installer.org/>`_::
|
||||
|
||||
$ pip install twython
|
||||
|
||||
or, with `easy_install <http://pypi.python.org/pypi/setuptools>`_::
|
||||
|
||||
$ easy_install twython
|
||||
|
||||
But, hey... `that's up to you <http://www.pip-installer.org/en/latest/other-tools.html#pip-compared-to-easy-install>`_.
|
||||
|
||||
|
||||
Source Code
|
||||
-----------
|
||||
|
||||
Twython is actively maintained on GitHub
|
||||
|
||||
Feel free to clone the repository::
|
||||
|
||||
git clone git://github.com/ryanmcgrath/twython.git
|
||||
|
||||
`tarball <https://github.com/ryanmcgrath/twython/tarball/master>`_::
|
||||
|
||||
$ curl -OL https://github.com/ryanmcgrath/twython/tarball/master
|
||||
|
||||
`zipball <https://github.com/ryanmcgrath/twython/tarball/master>`_::
|
||||
|
||||
$ curl -OL https://github.com/ryanmcgrath/twython/zipball/master
|
||||
|
||||
Now that you have the source code, install it into your site-packages directory::
|
||||
|
||||
$ python setup.py install
|
||||
8
docs/_build/html/_sources/usage/quickstart.txt
vendored
Normal file
8
docs/_build/html/_sources/usage/quickstart.txt
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
.. _quickstart:
|
||||
|
||||
Quickstart
|
||||
==========
|
||||
|
||||
.. module:: twython.api
|
||||
|
||||
Eager
|
||||
79
docs/_build/html/_sources/usage/starting_out.txt
vendored
Normal file
79
docs/_build/html/_sources/usage/starting_out.txt
vendored
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
.. _starting-out:
|
||||
|
||||
Starting Out
|
||||
============
|
||||
|
||||
This section is going to help you understand creating a Twitter Application, authenticating a user, and making basic API calls
|
||||
|
||||
Beginning
|
||||
---------
|
||||
|
||||
First, you'll want to head over to https://dev.twitter.com/apps and register an application!
|
||||
|
||||
After you register, grab your applications ``Consumer Key`` and ``Consumer Secret`` from the application details tab.
|
||||
|
||||
Now you're ready to start authentication!
|
||||
|
||||
Authentication
|
||||
--------------
|
||||
|
||||
First, you'll want to import Twython::
|
||||
|
||||
from twython import Twython
|
||||
|
||||
Now, you'll want to create a Twython instance with your ``Consumer Key`` and ``Consumer Secert``
|
||||
|
||||
::
|
||||
|
||||
APP_KEY = 'YOUR_APP_KEY'
|
||||
APP_SECET = 'YOUR_APP_SECRET'
|
||||
|
||||
twitter = Twython(APP_KEY, APP_SECRET)
|
||||
auth = twitter.get_authentication_tokens(callback_url='http://mysite.com/callback')
|
||||
|
||||
From the ``auth`` variable, save the ``oauth_token_secret`` for later use. In Django or other web frameworks, you might want to store it to a session variable::
|
||||
|
||||
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 Callback
|
||||
---------------------
|
||||
|
||||
After they authorize your application to access some of their account details, they'll be redirected to the callback url you specified in ``get_autentication_tokens``
|
||||
|
||||
You'll want to extract the ``oauth_token`` and ``oauth_verifier`` from the url.
|
||||
|
||||
Django example:
|
||||
::
|
||||
|
||||
OAUTH_TOKEN = request.GET['oauth_token']
|
||||
oauth_verifier = request.GET['oauth_verifier']
|
||||
|
||||
Now that you have the ``oauth_token`` and ``oauth_verifier`` stored to variables, you'll want to create a new instance of Twython and grab the final user tokens::
|
||||
|
||||
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_SECERT = final_step['oauth_token_secret']
|
||||
|
||||
The Twython API Table
|
||||
---------------------
|
||||
|
||||
In the Twython package is a file called ``endpoints.py`` which holds a dictionary of all Twitter API endpoints. This is so Twython's core ``api.py`` isn't cluttered with 50+ methods. We dynamically register these funtions when a Twython object is initiated.
|
||||
|
||||
Dynamic Function Arguments
|
||||
--------------------------
|
||||
|
||||
Keyword 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.
|
||||
|
||||
-----------------------
|
||||
|
||||
Now that you have your application tokens and user tokens, check out the :ref:`basic usage <basic-usage>` section.
|
||||
Loading…
Add table
Add a link
Reference in a new issue