Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.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收到回复特定推文的推文_Python_Search_Twitter_Tweepy - Fatal编程技术网

Python Tweepy收到回复特定推文的推文

Python Tweepy收到回复特定推文的推文,python,search,twitter,tweepy,Python,Search,Twitter,Tweepy,因此,我在Tweepy和Twitter数据挖掘方面做了大量工作,我想做的一件事是能够获得所有对特定推文的回复。我看过搜索api,但我不知道如何使用它,也不知道如何专门搜索回复特定推文的推文。有人有什么想法吗?谢谢大家。我已经创建了一个解决此类问题的方法。最好的方法是搜索用户的提及,然后通过回复id过滤这些提及。Dude/tte…你有没有先在谷歌搜索你的问题?我来帮你。是的,我做到了,就是这样。如果我的帖子不符合标准,我很抱歉,我还是新来的。我正在尽力。 user_name = "@nameofu

因此,我在Tweepy和Twitter数据挖掘方面做了大量工作,我想做的一件事是能够获得所有对特定推文的回复。我看过搜索api,但我不知道如何使用它,也不知道如何专门搜索回复特定推文的推文。有人有什么想法吗?谢谢大家。

我已经创建了一个解决此类问题的方法。最好的方法是搜索用户的提及,然后通过回复id过滤这些提及。

Dude/tte…你有没有先在谷歌搜索你的问题?我来帮你。是的,我做到了,就是这样。如果我的帖子不符合标准,我很抱歉,我还是新来的。我正在尽力。
user_name = "@nameofuser"

replies = tweepy.Cursor(api.search, q='to:{}'.format(user_name),
                                since_id=tweet_id, tweet_mode='extended').items()

while True:
    try:

        reply = replies.next()
        if not hasattr(reply, 'in_reply_to_status_id_str'):
            continue
        if str(reply.in_reply_to_status_id) == tweet_id:
           logging.info("reply of tweet:{}".format(reply.text))

    except tweepy.RateLimitError as e:
        logging.error("Twitter api rate limit reached".format(e))
        time.sleep(60)
        continue

    except tweepy.TweepError as e:
        logging.error("Tweepy error occured:{}".format(e))
        break

    except StopIteration:
        break

    except Exception as e:
        logger.error("Failed while fetching replies {}".format(e))
        break