I have a list of the specific status ids of tweets that I need to obtain. The tweepy documentation provides the following:
API.get_status(id)
Returns a single status specified by the ID parameter.
Parameters: id – The numerical ID of the status.
Return type: Status object
I can't work out how to use this or find any examples. Is this even the right thing?
My list of ids is 2240 items long and looks something like this:
response_ids = [717289507981107201, 717289501337509888, ..., 716684885411237888]
These ids were obtained from the 'in_response_to_status_id' field of tweets that I already have (I want to match the tweets I have to the tweets that they were written in response to).
I basically want to write something like
for id in response_ids:
tweet = API.get_status(id)
Any help on how to do this, or advice about whether this is possible, much appreciated.
Think I've worked it out.
get_status
does seem to be the right thing to use, although I initially had some problems with pagination errors. I've hacked some code found in response to another similar problem to come up with this solution:
def paginate(iterable, page_size):
while True:
i1, i2 = itertools.tee(iterable)
iterable, page = (itertools.islice(i1, page_size, None),
list(itertools.islice(i2, page_size)))
if len(page) == 0:
break
yield page
index = 0
for page in paginate(response_ids, 1):
result = api.get_status(response_ids[index])._json
index += 1