Twitter API - Getting list of users who favorited

2019-02-04 15:29发布

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?

标签: twitter
1条回答
爷、活的狠高调
2楼-- · 2019-02-04 16:15

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
查看更多
登录 后发表回答