Twitter API - 获取收藏状态的用户列表 [英] Twitter API - Getting list of users who favorited a status
本文介绍了Twitter API - 获取收藏状态的用户列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过 Twitter API 获取收藏特定状态的用户列表.我可以看到每个状态都有它获得的收藏数量,但我需要收藏的用户列表.
I want to get a list of users who favorited a specific status through the Twitter API. I can see that each statuses have the amount of favorites it got but I need the list of users who made the favorite.
有什么想法可以实现吗?
Any ideas how this can be achieved?
推荐答案
这是在 Python 2.7.x
中实现的解决方法或 hack:
Here is a workaround or hack implemented in Python 2.7.x
:
import urllib2
import re
def get_user_ids_of_post_likes(post_id):
try:
json_data = urllib2.urlopen('https://twitter.com/i/activity/favorited_popup?id=' + str(post_id)).read()
found_ids = re.findall(r'data-user-id=\\"+\d+', json_data)
unique_ids = list(set([re.findall(r'\d+', match)[0] for match in found_ids]))
return unique_ids
except urllib2.HTTPError:
return False
# Example:
# https://twitter.com/golan/status/731770343052972032
print get_user_ids_of_post_likes(731770343052972032)
# ['13520332', '416273351', '284966399']
#
# 13520332 +> @TopLeftBrick
# 416273351 => @Berenger_r
# 284966399 => @FFrink
这篇关于Twitter API - 获取收藏状态的用户列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文