我想把所有推文都拉得比某个max_id更早。但是,我无法确定在我的请求中添加max_id的位置,以便推送比指定推文更旧的推文。我想这样做而不改变计数。到目前为止,这是我的代码:
import requests
import time
import json
import urllib
import urllib2
import datetime
import tweepy
ct = "INSERT CONSUMER TOKEN"
cs = "INSERT CONSUMER SECRET"
at = "INSERT ACCESS TOKEN"
acs = "INSERT CONSUMER SECRET"
count = 1
twitter = "transportgovuk"
consumer_token = ct
consumer_secret = cs
access_token = at
access_secret = acs
auth = tweepy.OAuthHandler(consumer_token,consumer_secret)
auth.set_access_token(access_token,access_secret)
api = tweepy.API(auth)
max_id = "724916468975046656"
for status in tweepy.Cursor(api.user_timeline,twitter).items(count):
print status
有没有办法在指定的max_id之后直接拉出推文而不改变计数?
答案 0 :(得分:0)
看起来你只需将max_id添加到tweepy.Cursor for循环中就像这样:
import requests
import time
import json
import urllib
import urllib2
import datetime
import tweepy
ct = "INSERT CONSUMER TOKEN"
cs = "INSERT CONSUMER SECRET"
at = "INSERT ACCESS TOKEN"
acs = "INSERT CONSUMER SECRET"
count = 1
twitter = "transportgovuk"
consumer_token = ct
consumer_secret = cs
access_token = at
access_secret = acs
auth = tweepy.OAuthHandler(consumer_token,consumer_secret)
auth.set_access_token(access_token,access_secret)
api = tweepy.API(auth)
status_ids= "724916468975046656"
for status in tweepy.Cursor(api.user_timeline,twitter,max_id=status_ids).items(count):
print status
那应该使用status_id“724916468975046656”来发送推文。如果您想要更多,请将您的计数更改为高于1的数字。