Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter API - Getting list of users who favorited a status

Tags:

twitter

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?

like image 902
Ran Avatar asked Mar 11 '15 09:03

Ran


People also ask

Can you see someone's favorites on Twitter?

How do I see what other people have liked? See what other people have liked by going to their profile: From the Twitter for iOS or Android app: Navigate to the profile of the account and tap Likes. Via twitter.com: Navigate to the profile page of the account and click on Likes at the top of their Tweet timeline.

What is favorite count in Twitter API?

The favorite_count provides the number of times the tweet has been favorited. In the case of a retweet, favorite_count is the favorite count of the source tweet. (This is similar to retweet_count.)

Can people see my favorited tweets?

In addition, people can see your Likes from your profile page. There's a “Likes” tab right there, which anyone can click in order to see every single tweet you've liked. That's right: anyone who wants to can scroll through every tweet you've ever liked.


1 Answers

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
like image 183
Darius Avatar answered Oct 12 '22 23:10

Darius