We use pagination a lot in Twitter API development. Iterating through
timelines, user lists, direct messages, etc. In order to perform
-pagination we must supply a page/cursor parameter with each of our
+pagination, we must supply a page/cursor parameter with each of our
requests. The problem here is this requires a lot of boiler plate code
just to manage the pagination loop. To help make pagination easier and
-require less code Tweepy has the Cursor object.
+require less code, Tweepy has the Cursor object.
Old way vs Cursor way
---------------------
First let's demonstrate iterating the statuses in the authenticated
-user's timeline. Here is how we would do it the "old way" before
+user's timeline. Here is how we would do it the "old way" before the
Cursor object was introduced::
page = 1
break
page += 1 # next page
-As you can see we must manage the "page" parameter manually in our
-pagination loop. Now here is the version of the code using Cursor
+As you can see, we must manage the "page" parameter manually in our
+pagination loop. Now here is the version of the code using the Cursor
object::
for status in tweepy.Cursor(api.user_timeline).items():
process_status(status)
Now that looks much better! Cursor handles all the pagination work for
-us behind the scene so our code can now focus entirely on processing
+us behind the scenes, so our code can now focus entirely on processing
the results.
Passing parameters into the API method
tweepy.Cursor(api.user_timeline, id="twitter")
-Now Cursor will pass the parameter into the method for us when ever it
+Now Cursor will pass the parameter into the method for us whenever it
makes a request.
Items or Pages
--------------
-So far we have just demonstrated pagination iterating per an
-item. What if instead you want to process per a page of results? You
+So far we have just demonstrated pagination iterating per
+item. What if instead you want to process per page of results? You
would use the pages() method::
for page in tweepy.Cursor(api.user_timeline).pages():
Include Tweets > 140 Characters
-------------------------------
-Since twitter increased the maximum characters allowed in a tweet from 140 to 280, you may notice that tweets greater than 140 characters are truncated with a ...
-If you want your results to include the full text of the long tweets make these simple changes:
+Since twitter increased the maximum number of characters allowed in a tweet from 140 to 280, you may notice that tweets greater than 140 characters are truncated with ...
+If you want your results to include the full text of the long tweets, make these simple changes:
- add the argument tweet_mode='extended' to your Cursor object call
-- change your usages of .text to .full_text
+- change your usage of .text to .full_text
.. code-block :: python