getting_started.rst 1.67 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
.. _getting_started:


***************
Getting started
***************

Introduction
============

If you are new to Tweepy, this is the place to begin. The goal of this
tutorial is to get you set-up and rolling with Tweepy. We won't go
into too much detail here, just some important basics.

Hello Tweepy
============

.. code-block :: python

   import tweepy
Aaron Hill's avatar
Aaron Hill committed
21
22
23
24
25

   auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
   auth.set_access_token(access_token, access_token_secret)

   api = tweepy.API(auth)
26
   
Aaron Hill's avatar
Aaron Hill committed
27
   public_tweets = api.home_timeline()
28
29
30
   for tweet in public_tweets:
       print tweet.text

Aaron Hill's avatar
Aaron Hill committed
31
32
33
This example will download your home timeline tweets and print each
one of their texts to the console. Twitter requires all requests to
use OAuth for authentication.
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
The :ref:`auth_tutorial` goes into more details about authentication.

API
===

The API class provides access to the entire twitter RESTful API
methods. Each method can accept various parameters and return
responses. For more information about these methods please refer to
:ref:`API Reference <api_reference>`.

Models
======

When we invoke an API method most of the time returned back to us will
be a Tweepy model class instance. This will contain the data returned
from Twitter which we can then use inside our application. For example
the following code returns to us an User model::

   # Get the User object for twitter...
   user = tweepy.api.get_user('twitter')

55
Models contain the data and some helper methods which we can then
56
57
58
59
60
61
62
63
64
use::

   print user.screen_name
   print user.followers_count
   for friend in user.friends():
      print friend.screen_name

For more information about models please see ModelsReference.