Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用tweepy获取具有特定状态ID的推文_Python_Twitter_Status_Tweepy - Fatal编程技术网

Python 使用tweepy获取具有特定状态ID的推文

Python 使用tweepy获取具有特定状态ID的推文,python,twitter,status,tweepy,Python,Twitter,Status,Tweepy,我有一个我需要获得的tweet的特定状态ID的列表。 tweepy文档提供了以下内容: 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 我不知道如何使用这个,也找不到任何例子。 这是对的吗 我的ID列表有2240个条目,如下所示: re

我有一个我需要获得的tweet的特定状态ID的列表。 tweepy文档提供了以下内容:

 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
我不知道如何使用这个,也找不到任何例子。 这是对的吗

我的ID列表有2240个条目,如下所示:

response_ids = [717289507981107201, 717289501337509888, ..., 716684885411237888]
这些id是从我已经拥有的tweet的“in_response_to_status_id”字段中获得的(我想将我拥有的tweet与它们为响应而编写的tweet进行匹配)

我基本上想写一些像

for id in response_ids:
    tweet = API.get_status(id)

非常感谢您对如何做到这一点的任何帮助,或者关于这一点是否可行的建议。

我想我已经解决了

get_status
似乎是正确的选择,尽管我最初在分页错误方面遇到了一些问题。我已经破解了一些代码,这些代码是为了响应另一个问题而找到的:

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

最好使用“statuses\u lookup”命令。更多信息请参见下面的链接

在运行以下程序之前,获取使用者密钥和令牌

import tweepy
consumer_key = xxxx
consumer_secret = xxxx
access_token = xxxx
access_token_secret = xxxx

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

api = tweepy.API(auth)

tweets = api.statuses_lookup(id_list) # id_list is the list of tweet ids
tweet_txt = []
for i in tweets:
    tweet_txt.append(i.text)