I want to block people who like my tweets on python's tweet.

Asked 2 years ago, Updated 2 years ago, 82 views

multipost with teratail.
https://teratail.com/questions/111320

Tired of spam accounts that indiscriminately like my tweets on Twitter, I tried to automatically block them on python's tweet
I was thinking about it, but I'm having a hard time because I don't know how to get the tweet ID of the person who liked my tweet.

I think I translated the API reference for tweet through automatic translation, but the method to get the tweet ID of the person who liked it is
I thought it didn't exist.
If there is such a method, please let me know.
Also, please let me know if there is another way to get it.
I have already configured various keys, and I have created an API instance to get my tweets and their IDs.

Eventually, it automatically blocks accounts with 21 followers among those who have liked my tweets on python's tweet
I would like to make it into a script.

Thank you for your cooperation.

python twitter

2022-09-30 13:53

1 Answers

As you looked into it yourself, there seems to be no way to get a list of users who liked it in the official API. There was someone who wrote his own Python code, so would this be helpful?

How to "get a user who likes" that does not exist in TwitterAPI

import urlib.request
import re

# # https://stackoverflow.com/questions/28982850/twitter-api-getting-list-of-users-who-favorited-a-status

def get_favoritters(post_id):
    try:
        json_data=urlib.request.urlopen('https://twitter.com/i/activity/favorited_popup?id='+str(post_id)) .read()
        json_data=json_data.decode("utf8")
        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 urllib.request.HTTPError:
        return False

Also, as mentioned in the comments in the code, if you use the above URL, please look at the English version of SO and see
It appears that the code was rewritten for Python 3.x.The original question was for Python 2.x.

Twitter API-Getting list of users who favorite a status-Stack Overflow


2022-09-30 13:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.