Wednesday, June 5, 2013

tweepy-get users timeline status from twitter in python

import urllib, json
import sys
import tweepy
from tweepy import OAuthHandler

def twitter_fetch(screen_name = "BBCNews",maxnumtweets=10):
    'Fetch tweets from @BBCNews'
    # API described at

    consumer_token = '' #substitute values from twitter website
    consumer_secret = ''
    access_token = ''
    access_secret = ''
    auth = tweepy.OAuthHandler(consumer_token,consumer_secret)
    api  = tweepy.API(auth)
    #api.update_status('Hello -tweepy + oauth!')

    for status in tweepy.Cursor(api.user_timeline,id=screen_name).items(2):
        print status.text+'\n'


if __name__ == '__main__':

YOu can obtain these tokens by registering your app with twitter(mandatory) - Keep them private.


Mohan Krishna Rachumallu said...

Thanks. Nice post

Nishant Nawarkhede said...

Nice Post, I am trying to do same using tweepy version 2.3 , I am getting following error ,

Traceback (most recent call last):
File "D:\Workspace\newtwiiter\", line 37, in
File "D:\Workspace\newtwiiter\", line 31, in twitter_fetch
for status in tweepy.Cursor(api.user_timeline,id=screen_name).items(2):
File "D:\Workspace\newtwiiter\tweepy\", line 181, in next
self.current_page =
File "D:\Workspace\newtwiiter\tweepy\", line 101, in next
old_parser = self.method.__self__.parser
AttributeError: 'function' object has no attribute '__self__'

Whats this error ? Can you please help me ?