Giter Site home page Giter Site logo

d60 / twikit Goto Github PK

View Code? Open in Web Editor NEW
657.0 7.0 71.0 3.77 MB

Twitter API Scraper | Without an API key | Twitter Internal API | Free | Twitter scraper | Twitter Bot

Home Page: https://twikit.readthedocs.io/en/latest/twikit.html

License: MIT License

Python 100.00%
api-wrapper free twitter twitter-api wrapper x python python3 bot client

twikit's People

Contributors

anhzhang1994 avatar d60 avatar evgeniy-kalkin avatar gormanfletcher avatar heiiow2 avatar mudassarzahid avatar nennneko5787 avatar pothitos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

twikit's Issues

Version 1.1.14; Update on Group DM

Hello! I have released version 1.1.14. The main content is regarding group DM. Here is how the detailed changes are shown.

Additions:

Client.send_dm_to_group: sends a message to a group.
Client.get_group_dm_history: retrieves message history of a group.
Client.get_group: retrieves group by ID.
Client.add_members_to_group: adds members to group.
Client.change_group_name: changes the name of the group.

Group: Class that represents a group. It has information about the group and methods for manipulating the group.
GroupMessage: Class representing the group's message.

I made the same change for the asynchronous version of the client.

For more information on this change, please see the documentation.
sync: https://twikit.readthedocs.io/en/latest/twikit.html#twikit.client.Client.send_dm_to_group
async: https://twikit.readthedocs.io/en/latest/twikit.twikit_async.html#twikit.client.Client.send_dm_to_group

Fixes:

Fixed a bug that an error occurred when getting trend with get_trend function.

If you have any bugs regarding this update, please let me know.

Update login process

Hi, Can you modify the login process so that, in situations requiring 2FA or a verification step, it throws an exception instead of prompting for input? If such an exception occurs, could we attempt to log in again, possibly passing the 2FA code directly into the login function? Alternatively, could you create a function that sets this code and initiates the login process? The current method, which falls back to an input prompt, cannot be automated.

https://github.com/d60/twikit/blob/main/twikit/client.py#L244
https://github.com/d60/twikit/blob/main/twikit/client.py#L258

version 1.1.6 build_query

The build_query function has been added in version 1.1.6.
This function allows you to easily add search query options (e.g., "from:" or "since:").
The function can be used as follows:

from twikit import build_query

base_query = 'programming'
options = {
    'hashtags': ['python'],
    'since': '2022-1-1',
    'until': '2024-1-1',
}

constructed_query = build_query(base_query, options)
-> "programming #python since:2022-1-1 until:2024-1-1"

For more information, please see the documentation.
https://twikit.readthedocs.io/en/latest/twikit.html#twikit.utils.build_query

ERROR:_get_user_friendship

user_info = find_dict(item, 'result')

In some cases, an empty list may be returned, which I have encountered.

Using find_dict(item, 'result')[0] will return an index error.

TweetWithVisibilityResults results in critical failure

You can see that with a normal "Tweet"

The structure begins as

{'__typename': 'Tweet', 'rest_id': '1756093204984693206', ...

When you have a typename of "TweetWithVisibilityResults"

This will result in an error as the 'rest_id' is inside the "tweet" object and is inaccessible. It is presumable that the rest of the assignments will fail as well as a consequence.

I have provided a redacted example data structure. Should be simple to add handling for this

{
    "__typename": "TweetWithVisibilityResults",
    "tweet": {
        "rest_id": "",
        "core": {
            "user_results": {
                "result": {
                    "__typename": "User",
                    "id": "",
                    "rest_id": "",
                    "affiliates_highlighted_label": {},
                    "has_graduated_access": true,
                    "is_blue_verified": false,
                    "profile_image_shape": "Circle",
                    "legacy": {
                        "can_dm": true,
                        "can_media_tag": false,
                        "created_at": "",
                        "default_profile": false,
                        "default_profile_image": false,
                        "description": "",
                        "entities": {
                            "description": {
                                "urls": []
                            }
                        },
                        "fast_followers_count": 0,
                        "favourites_count": 0,
                        "followers_count": 0,
                        "friends_count": 0,
                        "has_custom_timelines": true,
                        "is_translator": false,
                        "listed_count": 0,
                        "location": "",
                        "media_count": 0,
                        "name": "",
                        "normal_followers_count": 0,
                        "pinned_tweet_ids_str": [
                            ""
                        ],
                        "possibly_sensitive": false,
                        "profile_image_url_https": "",
                        "profile_interstitial_type": "",
                        "screen_name": "",
                        "statuses_count": 0,
                        "translator_type": "none",
                        "verified": false,
                        "want_retweets": false,
                        "withheld_in_countries": []
                    },
                    "professional": {
                        "rest_id": "",
                        "professional_type": "Creator",
                        "category": []
                    }
                }
            }
        },
        "unmention_data": {},
        "edit_control": {
            "edit_tweet_ids": [
                ""
            ],
            "editable_until_msecs": "",
            "is_edit_eligible": true,
            "edits_remaining": "5"
        },
        "is_translatable": true,
        "views": {
            "count": "",
            "state": "EnabledWithCount"
        },
        "source": "",
        "legacy": {
            "bookmark_count": 0,
            "bookmarked": false,
            "created_at": "",
            "conversation_control": {
                "policy": "Community",
                "conversation_owner_results": {
                    "result": {
                        "__typename": "User",
                        "legacy": {
                            "screen_name": ""
                        }
                    }
                }
            },
            "conversation_id_str": "",
            "display_text_range": [],
            "entities": {
                "hashtags": [],
                "symbols": [],
                "timestamps": [],
                "urls": [],
                "user_mentions": []
            },
            "favorite_count": 0,
            "favorited": false,
            "full_text": "",
            "is_quote_status": false,
            "lang": "",
            "limited_actions": "limited_replies",
            "quote_count": 0,
            "reply_count": 0,
            "retweet_count": 0,
            "retweeted": false,
            "user_id_str": "",
            "id_str": ""
        },
        "quick_promote_eligibility": {
            "eligibility": "IneligibleNotProfessional"
        }
    },
    "limitedActionResults": {
        "limited_actions": [
            {
                "action": "Reply",
                "prompt": {
                    "__typename": "CtaLimitedActionPrompt",
                    "cta_type": "SeeConversation",
                    "headline": {
                        "text": "Who can reply?",
                        "entities": []
                    },
                    "subtext": {
                        "text": "People the author mentioned can reply",
                        "entities": []
                    }
                }
            }
        ]
    }
}```

Version 1.1.10

Version 1.1.10 Changelog:

1.

Added view_count attribute to Tweet class to access the number of views of a tweet.

2.

Introduced a new method to get engagement analysis:
get_retweeters: This method retrieves a list of users who retweeted a given tweet.
get_favoriters: This method retrieves the list of users who favorited a given tweet.

client.get_trends('news') never returns

Hello,
I have tried using the "get_trends" function to retrieve the trending names and the script hangs. If I leave it this way for a minute or more, I get "RecursionError: maximum recursion depth exceeded". Other function like "get_tweets" do work thought.
Thanks,
George.

is it possible to write to group dialogs and receive a message from them?

Good afternoon, first of all I am very grateful for your app it is a Herculean effort and you are a hero for me.

I have such a question, is it possible to receive messages and write in group chats? If not, can you suggest the direction where to dig I will then try to add this functionality and send to the pool requester.

Version 1.1.16 Added list

Hello! Version 1.1.16 has been released. The main updates in this version revolve around list-related functionalities.

Added:

Client.create_list: Creates a list.
Client.edit_list_banner: Modifies the banner image of a list.
Client.delete_list_banner: Deletes the banner of a list.
Client.edit_list: Edits the information of a list.
Client.add_list_member: Adds a member to a list.
Client.remove_list_member: Removes a member from a list.
Client.get_list: Retrieves a list from its ID.
Client.get_list_tweets: Retrieves tweets from a list.

Client: A class containing information and methods related to lists.

conversation_control is now supported

version 1.1.5
By specifying the argument, conversation_control, to the create_tweet method, you can restrict the users who can reply to that tweet.
The modes that can be specified are as follows

followers: Limits replies to followers only.
verified: Limits replies to verified accounts only.
mentioned: Limits replies to mentioned accounts only.

For example:

create_tweet('text', conversation_control='followers')

notify types to Python static analyzer

Hi, there. I want to use this library with static analyzer such as mypy or something else.

notifying type to static analyzer, I suppose use following method

  1. adding py.dyped in ./twikit
    we just put empty file.

  2. adding section package_data to setup function parameter.

import re

from setuptools import setup

with open('README.md', encoding='utf-8') as f:
    long_description = f.read()

with open('./twikit/__init__.py') as f:
    version = re.findall(r"__version__ = '(.+)'", f.read())[0]

setup(
    name='twikit',
    version=version,
    install_requires=['httpx', 'fake_useragent'],
    package_data={'twikit': ['py.typed']},                                                              # Add this line
    description='Twitter API wrapper for python with **no API key required**.',
    long_description=long_description,
    long_description_content_type='text/markdown',
    license='MIT',
    url='https://github.com/d60/twikit'
)

This is reference. Need more information, please look following url.
https://peps.python.org/pep-0561/

I hope the project continues to grow.
Thank you for reading.

tweets.next() fails on key 'legacy'

  File "c:\Python312\Lib\runpy.py", line 198, in _run_module_as_main
    return _run_code(code, main_globals, None,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Python312\Lib\runpy.py", line 88, in _run_code
    exec(code, run_globals)
  File "c:\Users\chick\.vscode-insiders\extensions\ms-python.debugpy-2024.3.10611007-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
    cli.main()
  File "c:\Users\chick\.vscode-insiders\extensions\ms-python.debugpy-2024.3.10611007-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "c:\Users\chick\.vscode-insiders\extensions\ms-python.debugpy-2024.3.10611007-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "c:\Users\chick\.vscode-insiders\extensions\ms-python.debugpy-2024.3.10611007-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\chick\.vscode-insiders\extensions\ms-python.debugpy-2024.3.10611007-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "c:\Users\chick\.vscode-insiders\extensions\ms-python.debugpy-2024.3.10611007-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "E:\Projects\someProj.py", line 25, in <module>
    main()
  File "E:\Projects\someProj.py", line 15, in main
    tweets = get_user_kind_of_tweets(user[0].id, 'Tweets', start_time_datetime)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Projects\someProj.py", line 59, in get_user_kind_of_tweets   
    raise e
  File "E:\Projects\someProj.py", line 51, in get_user_kind_of_tweets   
    tweets = tweets.next()
             ^^^^^^^^^^^^^
  File "c:\Python312\Lib\site-packages\twikit\utils.py", line 179, in next
    return self.__fetch_next_result()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Python312\Lib\site-packages\twikit\client.py", line 1608, in <lambda>
    lambda:self.get_user_tweets(
           ^^^^^^^^^^^^^^^^^^^^^
  File "c:\Python312\Lib\site-packages\twikit\client.py", line 1601, in get_user_tweets  
    tweet = Tweet(self, tweet_info, User(self, user_info))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Python312\Lib\site-packages\twikit\tweet.py", line 167, in __init__
    data['card']['legacy']['name'].startswith('poll')
    ~~~~~~~~~~~~^^^^^^^^^^
KeyError: 'legacy'

Version 1.1.22 Added block and mute

Hello. I have released version 1.1.22.

Additions:
Client.block_user: block a user.
Client.unblock_user: unblock a user.
Client.mute_user: mute a user
Client.unmute_user: unmute a user.

user.get_tweets('Tweets', count=10) At issue

I'm not sure if it's a problem with my code, here's my code:
tweets = await user.get_tweets('Tweets', count=10)
for tweet in tweets:
print(tweet.id)
print('====================')
The number printed is greater than 10, and the data obtained is incomplete (the latest tweet cannot be obtained)

can't login in in AWS

root@spiders-54696c5948-qfkt8:/spider# python test.py
Traceback (most recent call last):
File "/spider/test.py", line 11, in
client.login(
File "/usr/local/lib/python3.9/site-packages/twikit/client.py", line 134, in login
guest_token = self._get_guest_token()
File "/usr/local/lib/python3.9/site-packages/twikit/client.py", line 58, in _get_guest_token
response = self.http.post(
File "/usr/local/lib/python3.9/site-packages/twikit/http.py", line 54, in post
return self.request('POST', url, **kwargs)
File "/usr/local/lib/python3.9/site-packages/twikit/http.py", line 42, in request
raise TooManyRequests(message)
twikit.errors.TooManyRequests: status: 429, message: "{"code":88,"message":"Rate limit exceeded."}"
root@spiders-54696c5948-qfkt8:/spider#

Version 1.1.15 Added logout method

Hello! I have just now released version 1.1.15. This update adds the Client.logout method. It disables the CSRF token associated with the account you are logging into and logs you out of the account.

Now Supporting Asynchronous Operations.

Twikit now supports asynchronous processing. By incorporating this, you can take advantage of asynchronous programming in Twikit. Use the snippet below to import an asynchronous version of the client:

from twikit.twikit_async import Client

More detailed examples will be uploaded soon.

Forbidden: status: 403,

I got this error. Can not tweet


Forbidden Traceback (most recent call last)
in <cell line: 1>()
----> 1 client.create_tweet(
2 text='Example Tweet'
3 )

2 frames
/usr/local/lib/python3.10/dist-packages/twikit/client.py in create_tweet(self, text, media_ids, poll_uri, reply_to, conversation_control)
701 'features': FEATURES,
702 }
--> 703 response = self.http.post(
704 Endpoint.CREATE_TWEET,
705 data=json.dumps(data),

/usr/local/lib/python3.10/dist-packages/twikit/http.py in post(self, url, **kwargs)
52
53 def post(self, url, **kwargs) -> httpx.Response:
---> 54 return self.request('POST', url, **kwargs)
55
56 def _remove_duplicate_ct0_cookie(self) -> None:

/usr/local/lib/python3.10/dist-packages/twikit/http.py in request(self, method, url, **kwargs)
34 raise Unauthorized(message)
35 elif status_code == 403:
---> 36 raise Forbidden(message)
37 elif status_code == 404:
38 raise NotFound(message)

Forbidden: status: 403, message: ""

Auto-authorization by code

Good afternoon at the moment I am facing a problem with auto-authorization by confirmation code.
The login function returns me the following method and how I can pass the code I don't quite understand yet.

{
  "flow_token": "g;170740332360356705:-1707403323829:YS97emnJqDUS31DlbAHsYh0y:9",
  "status": "success",
  "subtasks": [
    {
      "subtask_id": "LoginAcid",
      "enter_text": {
        "header": {
          "primary_text": {
            "text": "Help us keep your account safe.",
            "entities": []
          },
          "secondary_text": {
            "text": "Verify your identity by entering the email address associated with your X account.\t\nHint: ru***********@h******.***",
            "entities": []
          },
          "user": {
            "id": 1140550256,
            "id_str": "1140550256",
            "name": "Aurora\ud83d\ude08",
            "screen_name": "Aujanehan",
            "location": "Girl wanna you\ud83e\udd75",
            "url": "https://t.co/R25dSC9wBj",
            "description": "Your guide to the world of naked girls\ud83e\udd75",
            "protected": false,
            "followers_count": -1,
            "friends_count": -1,
            "listed_count": null,
            "created_at": "Fri Feb 01 19:34:50 +0000 2013",
            "favourites_count": -1,
            "utc_offset": null,
            "time_zone": null,
            "geo_enabled": false,
            "verified": false,
            "statuses_count": -1,
            "lang": null,
            "contributors_enabled": false,
            "is_translator": false,
            "is_translation_enabled": false,
            "profile_background_color": "",
            "profile_background_image_url": null,
            "profile_background_image_url_https": null,
            "profile_background_tile": false,
            "profile_image_url": "http://pbs.twimg.com/profile_images/1755273871845101568/HxkQrXZF_normal.jpg",
            "profile_image_url_https": "https://pbs.twimg.com/profile_images/1755273871845101568/HxkQrXZF_normal.jpg",
            "profile_link_color": "",
            "profile_sidebar_border_color": "",
            "profile_sidebar_fill_color": "",
            "profile_text_color": "",
            "profile_use_background_image": false,
            "default_profile": true,
            "default_profile_image": false,
            "can_media_tag": null,
            "following": null,
            "follow_request_sent": null,
            "notifications": null,
            "muting": null,
            "blocking": null,
            "blocked_by": null,
            "translator_type": "none",
            "withheld_in_countries": [],
            "followed_by": null
          }
        },
        "detail_text": {
          "text": "Why am I being asked for this information?\n\nReport a problem",
          "entities": [
            {
              "from_index": 0,
              "to_index": 42,
              "navigation_link": {
                "link_type": "chromeless_web_link",
                "link_id": "login_issues_link",
                "url": "https://help.twitter.com/managing-your-account/additional-information-request-at-login"
              }
            },
            {
              "from_index": 44,
              "to_index": 60,
              "navigation_link": {
                "link_type": "chromeless_web_link",
                "link_id": "report_problem_link",
                "url": "https://help.twitter.com/forms/account-access/regain-access"
              }
            }
          ]
        },
        "hint_text": "Email address",
        "multiline": false,
        "auto_capitalization_type": "none",
        "auto_correction_enabled": false,
        "keyboard_type": "email",
        "next_link": {
          "link_type": "task",
          "link_id": "next_link",
          "label": "Next"
        }
      },
      "subtask_back_navigation": "cancel_flow"
    }
  ]
}

list index out of range in search_tweet

tweets = client.search_tweet('#elonmusk', 'Latest')
File "x\twikit\client.py", line 469, in search_tweet
instructions = find_dict(response, 'instructions')[0]

IndexError: list index out of range

i got error but i don't now why?

Tweet.replies() doesn't contain all the replies from a tweet.

Having an issue where Tweets.replies() doesn't get all the tweets in a tweet thread.

For example, if I pull this tweet from @Destiny2Team, I only get the initial tweet I pulled as the base object and in the tweet.replies object, I don't get all the tweet replies in the chain.

When I get the tweet the using user.get_tweets() and go to that specific tweet (currently index 16), I only get the last 2 tweets in that thread for that specific entry.

Pasted image 20240328201130

>>> user = client.get_user_by_screen_name('Destiny2Team')
>>> tweets = user.get_tweets('Tweets')
>>> len(tweets[16].replies)  # Should return 7
2

When I get the tweet using client.get_tweet_by_id(), I only get the last 5 tweets in that thread.

Pasted image 20240328202742

>>> tweet = client.get_tweet_by_id(1766274441192046916)
>>> len(tweet.replies)  # Should return 7
5

I assume that on the backend, twikit is limiting how many replies it will look for. Is it possible to have a user-defined setting where that reply limit can be raised/lowered for each implementation?

For some Twitter accounts get_user_following() results in list index out of range


check_num = 0
user_prob = []

for k in df_acc_list:
    user_id_store = []
    check_num = check_num + 1
    try:
        user_following3 = client.get_user_following(k)
    except:
        print(str(k) + ' was a problem.')
        user_prob.append(k)
        time.sleep(20)
        continue
    
    for i in range(len(user_following3)):
        try:
            des_url = user_following3[i].description_urls[0]['expanded_url']
        except:
            des_url = None
        user_id_store.append({
            'User_ID':k,
            'Following_ID': user_following3[i].id,
            'Verified': user_following3[i].is_blue_verified,
            'User_Description': user_following3[i].description,
            'Description_URL': des_url,
            'Like_Count': user_following3[i].favourites_count,
            'Follower_Count': user_following3[i].followers_count,
            'Friend_Count': user_following3[i].following_count,
            'Location': user_following3[i].location,
            'UserName': user_following3[i].name,
            'ScreenName': user_following3[i].screen_name,
            'Total_Posts':user_following3[i].statuses_count,
            'User_Verified': user_following3[i].verified
        })

    time.sleep(20)
    if check_num%100 == 0:
        time.sleep(60*3)

For some accounts client.get_user_following(k) throws IndexError: list index out of range. Checked with two different versions 1.3.16 and 1.4.7.

Error Message:

IndexError                                Traceback (most recent call last)
/tmp/ipykernel_162588/1999871064.py in <module>
----> 1 client.get_user_following(user_id = '370279585')

~/anaconda3/lib/python3.9/site-packages/twikit/client.py in get_user_following(self, user_id, count, cursor)
   2472             A list of User objects representing the users being followed.
   2473         """
-> 2474         return self._get_user_friendship(
   2475             user_id,
   2476             count,

~/anaconda3/lib/python3.9/site-packages/twikit/client.py in _get_user_friendship(self, user_id, count, endpoint, cursor)
   2367             entry_id = item['entryId']
   2368             if entry_id.startswith('user'):
-> 2369                 user_info = find_dict(item, 'result')[0]
   2370                 results.append(User(self, user_info))
   2371             elif entry_id.startswith('cursor-bottom'):

IndexError: list index out of range

Some tweets retrieved with get_tweet_by_id give list index out of range error

As explained in the title there are tweets for which i dont know why the result for the function get_tweet_by id is list index out of range. If I check other tweet the result is correct, so i do not think the account is at fault.

EXEMPLE CODE OF THIS PROBLEM:

try:
print("We try a tweet with id: 1764666449073758266")
tweet = client.get_tweet_by_id("1764666449073758266")
print(tweet)
# Access tweet attributes
print(
f'id: {tweet.id}',
f'text {tweet.text}',
sep='\n'
)
except:
print("It failed, we try another tweet, with id 1764666472948011274")
tweet = client.get_tweet_by_id("1764666472948011274")
print(tweet)
# Access tweet attributes
print(
f'id: {tweet.id}',
f'text {tweet.text}',
sep='\n'
)

We need the help of professionals😻

Good afternoon, we are working with your code, and we encountered one problem, since we do not have much knowledge in Python, we would like you to help us implement the connection of the back-end with the front-end. We have configured the application itself, but we cannot manage it with this application from the user panel😀 I think it's a two hour job for you, if you help us we will thank you🌍 of course $$, but keep in mind that we are newbies and we don't have much money🥲
Here are our telegram contacts @magic_agency_ua

tweets with hashtag

I want to get tweets using hashtags I could not find which function I should use in the documentation section.

Reading all likes of user

Similar to #2

I would love to be able to get recent likes made (say last 500 likes).

I can export all data of X account and that should in theory include all likes so no need to be able to get all likes although that would be nice too. Just in my case that's more than 150,000 likes and I don't think that would work with a python client like this?

But yea, would love to be able to get likes from my account.

My use case for both this and bookmarks is that I want a reliable way to get things out from my X account (likes/bookmarks). I will be running Twikit on cron schedule (every day) to get all the latest bookmarks. Latest likes. Latests posts/replies made by me too.

ModuleNotFoundError: No module named 'twikit'

Traceback (most recent call last):
  File "******r\twiint.py", line 1, in <module>
    from twikit import Client
ModuleNotFoundError: No module named 'twikit'

This error comes when i try to run the below program

from twikit import Client
import os
import random

img_path = "/media/igpost/image/"
text_path = "/media/igpost/caption/"

USERNAME = ''
EMAIL = '@me.com'
PASSWORD = ''

client = Client('en-US')

client.login(
    auth_info_1=USERNAME ,
    auth_info_2=EMAIL,
    password=PASSWORD
)

Two Factor Authentication

Add a way to log in on 2fa-enabled accounts

'subtasks': [{'subtask_id': 'LoginTwoFactorAuthChallenge'

KeyError: 'rest_id' when pulling next set of tweets

Great package, thanks for the work put in thus far.

I'm trying to pull the timeline of tweets from a single user. With the code below I retrieve around 180 tweets before I get a KeyError on 'rest_id'. Is this indicating that it is out of Tweets to retrieve? According to user.statuses_count there should be a few thousand but that may be inaccurate.

USER_SCREEN_NAME = '***THE USER***'
user = client.get_user_by_screen_name(USER_SCREEN_NAME)

# Access user attributes
print(
    f'id: {user.id}',
    f'name: {user.name}',
    f'followers: {user.followers_count}',
    f'tweets count: {user.statuses_count}',
    sep='\n'
)

retrieved = 0
total = user.statuses_count
saved_tweets = []
user_tweets = user.get_tweets('Tweets')
while retrieved < total:

    for tweet in user_tweets:
        saved_tweets.append(extract_fields(tweet))
    retrieved = len(saved_tweets)
    sleep_for = randint(1,4)
    print (f"Retrieved {retrieved}/{total} - sleeping {sleep_for} seconds.")
    sleep(sleep_for)
    user_tweets = user_tweets.next()
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[3], line 26
     24 print (f"Retrieved {retrieved}/{total} - sleeping {sleep_for} seconds.")
     25 sleep(sleep_for)
---> 26 user_tweets = user_tweets.next()

File ~/twikit/.venv/lib/python3.10/site-packages/twikit/utils.py:126, in Result.next(self)
    124 if self.__fetch_next_result is None:
    125     return Result([])
--> 126 return self.__fetch_next_result()

File ~/twikit/.venv/lib/python3.10/site-packages/twikit/client.py:1037, in Client.get_user_tweets.<locals>.<lambda>()
   1032         user = User(self, user_info)
   1033     results.append(Tweet(self, tweet_info, user))
   1035 return Result(
   1036     results,
-> 1037     lambda:self.get_user_tweets(
   1038         user_id, tweet_type, count, next_cursor),
   1039     next_cursor
   1040 )

File ~/twikit/.venv/lib/python3.10/site-packages/twikit/client.py:1033, in Client.get_user_tweets(self, user_id, tweet_type, count, cursor)
   1031         user_info = tweet_info['core']['user_results']['result']
   1032         user = User(self, user_info)
-> 1033     results.append(Tweet(self, tweet_info, user))
   1035 return Result(
   1036     results,
   1037     lambda:self.get_user_tweets(
   1038         user_id, tweet_type, count, next_cursor),
   1039     next_cursor
   1040 )

File ~/twikit/.venv/lib/python3.10/site-packages/twikit/tweet.py:59, in Tweet.__init__(self, client, data, user)
     56 self._data = data
     57 self.user = user
---> 59 self.id: str = data['rest_id']
     61 legacy = data['legacy']
     62 self.text: str = legacy['full_text']

KeyError: 'rest_id'

Returning all posts made by me

Similar to #2 and #3 I want to be able to return all the posts/replies made by me either across all time or in some interval (i.e. last 7 days). Perhaps it's possible already.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.