简体   繁体   English

在python中获取用户Twitter时间轴

[英]Getting a user twitter timeline in python

I need to get a users entire twitter timeline in python. 我需要在python中为用户提供整个Twitter时间轴。 I am using the following code with all the oauth keys: 我将以下代码与所有oauth密钥结合使用:

import twitter
api = twitter.api(consumer_key='',
                consumer_secret='', access_token_key='', access_token_secret='')
statuses = api.GetUserTimeline(username)
print [s.text for s in statuses]

however, it returns [] for every account i try 但是,我尝试的每个帐户都会返回[]

I have no idea what im doing wrong. 我不知道我在做什么错。 this is the first problem i've hade with python twitter. 这是我对python twitter的第一个问题。

Give it a try: 试试看:

#!\usr\bin\env python

import twitter

def oauth_login():
    # credentials for OAuth
    CONSUMER_KEY = ''
    CONSUMER_SECRET = ''
    OAUTH_TOKEN = '' 
    OAUTH_TOKEN_SECRET = ''
    # Creating the authentification
    auth = twitter.oauth.OAuth( OAUTH_TOKEN,
                                OAUTH_TOKEN_SECRET,
                                CONSUMER_KEY,
                                CONSUMER_SECRET )
    # Twitter instance
    twitter_api = twitter.Twitter(auth=auth)
    return twitter_api

# LogIn
twitter_api = oauth_login()
# Get statuses
statuses = twitter_api.statuses.user_timeline(screen_name='SpongeBob')
# Print text 
print [status['text'] for status in statuses]

I think you have to change your second line as following: 我认为您必须更改第二行,如下所示:

api = twitter.Api(consumer_key='', consumer_secret='', access_token_key='', access_token_secret='')

There is no api class, instead there is Api . 没有api类,而是Api Please have a look at documentation . 请看一下文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM