File: getting_started.rst

package info (click to toggle)
tweepy 4.12.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,488 kB
  • sloc: python: 6,042; makefile: 16; javascript: 10
file content (66 lines) | stat: -rw-r--r-- 1,719 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
.. _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

   auth = tweepy.OAuth1UserHandler(
      consumer_key, consumer_secret, access_token, access_token_secret
   )

   api = tweepy.API(auth)
   
   public_tweets = api.home_timeline()
   for tweet in public_tweets:
       print(tweet.text)

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.
The :ref:`authentication` documentation 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 a User model::

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

Models contain the data and some helper methods which we can then
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.