【问题标题】:adding parameters to tweepy api request向 tweepy api 请求添加参数
【发布时间】:2016-04-13 17:47:08
【问题描述】:

如何通过tweepy的api为twitter的请求设置参数。

#https://api.twitter.com/1.1/statuses/user_timeline.json?exclude_replies=true&include_rts=false
import tweepy

#assume tokens and secrets are declared

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

api = tweepy.API(auth)

status = api.user_timeline('xxxxxxxxx')

我从中得到的是来自用户在状态对象集合中的“推文和转发”,但是 我只希望返回用户的“推文”。在阅读了docs之后,我仍然不清楚如何修改请求网址

【问题讨论】:

    标签: python-2.7 twitter twitter-oauth tweepy


    【解决方案1】:

    我发现过滤从user_timeline返回的json对象是成功的。

    这将过滤掉用户的转发:

    for tweetObj in status:
        if hasattr(tweetObj, 'retweeted_status'):
            continue
        else:        
            print tweetObj #or whatever else you want to do
    

    但要回答您的问题,您可以像这样传递可选参数include_retweets

    status = api.user_timeline('xxxxxxxxx', include_retweets=False)
    

    我更喜欢第一种方法,因为 RT 仍然计入您的 countmaximum length 参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-18
      • 1970-01-01
      • 2019-09-24
      • 1970-01-01
      • 2015-07-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多