Tweepy:如何从用户那里获得超过20条推文?

时间:2015-05-22 22:06:14

标签: twitter tweepy

根据their docs

API.user_timeline([id/user_id/screen_name][, since_id][, max_id][, count][, page])

Returns the 20 most recent statuses posted from the authenticating user or the user specified. It’s also possible to request another user’s timeline via the id parameter.

那么如何才能从一个人的时间线中获得超过20条推文?文档没有显示...该用户是否需要进行身份验证?

2 个答案:

答案 0 :(得分:1)

您可以在page中使用page = 2参数。对于page = 1值1,您将从用户时间轴获得一组最新的20条推文,然后在进一步迭代中,当我们增加page = 2的值时,该方法将返回其他20条较早的推文。从第1页收到的最老的推文,您可以将其视为:

假设您在帐户中有120条推文(第一条推文是最早的,第120条推文是最新推文),那么:

  

no_of_pages = int(raw_input("Please enter the number of tweets: ")) for i in xrange(no_of_pages): API.user_timeline("@anmoluppal366", page = i) 会返回(100,120)

     

from scipy.interpolate import RectBivariateSpline # sample data data = np.random.rand(8, 4) width, height = data.shape xs = np.arange(width) ys = np.arange(height) # target size and interpolation locations new_width, new_height = width*2, height*2 new_xs = np.linspace(0, width-1, new_width) new_ys = np.linspace(0, height-1, new_height) # create the spline object, and use it to interpolate spline = RectBivariateSpline(xs, ys, data) #, kx=1, ky=1) for linear interpolation spline(new_xs, new_ys) 会返回(80,100)

     

......等等

我希望你现在有了页面的概念来实现这些东西。

public void getFilteredAirportList(String filteredText){

     System.out.println(filteredText); //returns Turkey    
     Predicate<Airport> filterCountry = u -> u.getCountry() == filteredText;
     Stream<Airport> airportFilteredList = airportList.stream().filter(filterCountry);
     airportFilteredList.forEach(u -> System.out.println(u.getCountry()));

}

答案 1 :(得分:0)

您还可以使用max_id参数。像

这样的东西
r0 = api.user_timeline("@donaldtrump") # gives 20 latest tweets
idlast = r0[-1].id # the last id of these 20
r1 = api.user_timeline("@donaldtrump", max_id = idlast) # next 20 tweets older or same age as idlast