Coder Social home page Coder Social logo

trevorhobenshield / twitter-api-client Goto Github PK

View Code? Open in Web Editor NEW
1.4K 23.0 188.0 31.71 MB

Implementation of X/Twitter v1, v2, and GraphQL APIs

Home Page: https://pypi.org/project/twitter-api-client

License: MIT License

Python 99.82% Shell 0.18%
api automation client scrape twitter async bot search twitter-api x

twitter-api-client's People

Contributors

trevorhobenshield 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

twitter-api-client's Issues

UnicodeEncodeError

When calling Scraper.tweet_by_rest_id, I received a UnicodeEncodeError when an emoji was in the author's name. Adding the encoding='utf-8' parameter to the write_text call (scraper.py:239) fixed the issue in my case.

Followers

Is there any method to get list of followers?

Logfile name and Location

Hi Trevor,

This is not a issue but more a request.
Would it be possible to define the logfile name (i.e. debug.log) or is that already possible?

More/updated documentation

Is there an updated or more complete documentation?
The one here or at pypi.org mentions, for example, the scraper.users() function, which doesn't exist, but I found the user_by_rest_id, I have to get this ID but after that it works as expected, and in the function scraper.tweets(), I see no arguments for limiting the results. I'm looking for a way to simply get the latest tweets' content for some accounts, but it's not clear how to optimally do it.

RuntimeError: uvloop does not support Windows

When I tried installing the package, it says RuntimeError: uvloop does not support Windows at the moment and tries to install the previous version, constantly failing.

Collecting twitter-api-client
  Downloading twitter_api_client-0.4.0-py3-none-any.whl (31 kB)
Requirement already satisfied: requests in c:\users\smarotta\pycharmprojects\generic_scraper\my_env\lib\site-packages (from twitter-api-client) (2.28.2)
Collecting aiohttp
  Downloading aiohttp-3.8.4-cp310-cp310-win_amd64.whl (319 kB)
     |████████████████████████████████| 319 kB 3.3 MB/s
Collecting ujson
  Downloading ujson-5.7.0-cp310-cp310-win_amd64.whl (41 kB)
     |████████████████████████████████| 41 kB 3.2 MB/s
Collecting tqdm
  Using cached tqdm-4.65.0-py3-none-any.whl (77 kB)
Collecting nest-asyncio
  Using cached nest_asyncio-1.5.6-py3-none-any.whl (5.2 kB)
Collecting uvloop
  Downloading uvloop-0.17.0.tar.gz (2.3 MB)
     |████████████████████████████████| 2.3 MB ... 
  Preparing metadata (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\smarotta\PycharmProjects\generic_scraper\my_env\Scripts\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\smarotta\\AppData\\Local\\Temp\\pip-install-nif41etr\\uvloop_8
0bd716f8c204c2fa6bf4ca3acf4967e\\setup.py'"'"'; __file__='"'"'C:\\Users\\smarotta\\AppData\\Local\\Temp\\pip-install-nif41etr\\uvloop_80bd716f8c204c2fa6bf4ca3acf4967e\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__
file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-
base 'C:\Users\smarotta\AppData\Local\Temp\pip-pip-egg-info-vpoz9gkn'
       cwd: C:\Users\smarotta\AppData\Local\Temp\pip-install-nif41etr\uvloop_80bd716f8c204c2fa6bf4ca3acf4967e\
  Complete output (5 lines):
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\smarotta\AppData\Local\Temp\pip-install-nif41etr\uvloop_80bd716f8c204c2fa6bf4ca3acf4967e\setup.py", line 8, in <module>
      raise RuntimeError('uvloop does not support Windows at the moment')
  RuntimeError: uvloop does not support Windows at the moment
  ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/ba/86/6dda1760481abf244cbd3908b79a4520d757040ca9ec37a79fc0fd01e2a0/uvloop-0.17.0.tar.gz#sha256=0ddf6baf9cf11a1a22c71487f39f15b2cf78eb5bde7e5b45fbb99e8a9d91b9e1 (from ht
tps://pypi.org/simple/uvloop/) (requires-python:>=3.7). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  Downloading uvloop-0.16.0.tar.gz (2.1 MB)
     |████████████████████████████████| 2.1 MB 6.4 MB/s            
  Preparing metadata (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\smarotta\PycharmProjects\generic_scraper\my_env\Scripts\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\smarotta\\AppData\\Local\\Temp\\pip-install-nif41etr\\uvloop_e
0152b8be51f4e07a55d19c8d580f419\\setup.py'"'"'; __file__='"'"'C:\\Users\\smarotta\\AppData\\Local\\Temp\\pip-install-nif41etr\\uvloop_e0152b8be51f4e07a55d19c8d580f419\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__
file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-
base 'C:\Users\smarotta\AppData\Local\Temp\pip-pip-egg-info-y9b9bc6h'
       cwd: C:\Users\smarotta\AppData\Local\Temp\pip-install-nif41etr\uvloop_e0152b8be51f4e07a55d19c8d580f419\
  Complete output (5 lines):
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\smarotta\AppData\Local\Temp\pip-install-nif41etr\uvloop_e0152b8be51f4e07a55d19c8d580f419\setup.py", line 8, in <module>
      raise RuntimeError('uvloop does not support Windows at the moment')
  RuntimeError: uvloop does not support Windows at the moment
  ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/ab/d9/22bbffa8f8d7e075ccdb29e8134107adfb4710feb10039f9d357db8b589c/uvloop-0.16.0.tar.gz#sha256=f74bc20c7b67d1c27c72601c78cf95be99d5c2cdd4514502b4f3eb0933ff1228 (from ht
tps://pypi.org/simple/uvloop/) (requires-python:>=3.7). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  Downloading uvloop-0.15.3.tar.gz (2.1 MB)
     |████████████████████████████████| 2.1 MB 6.4 MB/s            
  Preparing metadata (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\smarotta\PycharmProjects\generic_scraper\my_env\Scripts\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\smarotta\\AppData\\Local\\Temp\\pip-install-nif41etr\\uvloop_2
849d00d40e641f6862db90b603cca78\\setup.py'"'"'; __file__='"'"'C:\\Users\\smarotta\\AppData\\Local\\Temp\\pip-install-nif41etr\\uvloop_2849d00d40e641f6862db90b603cca78\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__
file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-
base 'C:\Users\smarotta\AppData\Local\Temp\pip-pip-egg-info-5fxrrfsb'
       cwd: C:\Users\smarotta\AppData\Local\Temp\pip-install-nif41etr\uvloop_2849d00d40e641f6862db90b603cca78\
  Complete output (5 lines):
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\smarotta\AppData\Local\Temp\pip-install-nif41etr\uvloop_2849d00d40e641f6862db90b603cca78\setup.py", line 8, in <module>
      raise RuntimeError('uvloop does not support Windows at the moment')
  RuntimeError: uvloop does not support Windows at the moment
  ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/41/49/d2cdac6450430f444d3df59ccd1abc8225ea51ffcecd9ac2e36b111074a4/uvloop-0.15.3.tar.gz#sha256=905f0adb0c09c9f44222ee02f6b96fd88b493478fffb7a345287f9444e926030 (from ht
tps://pypi.org/simple/uvloop/) (requires-python:>=3.7). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  Downloading uvloop-0.15.2.tar.gz (2.1 MB)
     |████████████████████████████████| 2.1 MB 6.8 MB/s            
  Preparing metadata (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\smarotta\PycharmProjects\generic_scraper\my_env\Scripts\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\smarotta\\AppData\\Local\\Temp\\pip-install-nif41etr\\uvloop_b
c66758d41254b98ad900842110ad588\\setup.py'"'"'; __file__='"'"'C:\\Users\\smarotta\\AppData\\Local\\Temp\\pip-install-nif41etr\\uvloop_bc66758d41254b98ad900842110ad588\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__
file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-
base 'C:\Users\smarotta\AppData\Local\Temp\pip-pip-egg-info-u7jkumt5'
       cwd: C:\Users\smarotta\AppData\Local\Temp\pip-install-nif41etr\uvloop_bc66758d41254b98ad900842110ad588\
  Complete output (5 lines):
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\smarotta\AppData\Local\Temp\pip-install-nif41etr\uvloop_bc66758d41254b98ad900842110ad588\setup.py", line 8, in <module>
      raise RuntimeError('uvloop does not support Windows at the moment')
  RuntimeError: uvloop does not support Windows at the moment
  ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/44/6e/0cb292e4e6ee1382e2ede458f90c94b4f990b261f738403ac45cb8183bc2/uvloop-0.15.2.tar.gz#sha256=2bb0624a8a70834e54dde8feed62ed63b50bad7a1265c40d6403a2ac447bce01 (from ht
tps://pypi.org/simple/uvloop/) (requires-python:>=

Search function not working

code:

from twitter.search import search

search(
        '(#dogs OR #cats) min_retweets:500',
    )

error:

2023-04-08 17:04:13,020.020 DEBUG: (#dogs OR #cats) min_retweets:500
2023-04-08 17:04:13,919.919 DEBUG: FAILED to combine search results, input length is 0: line 1 column 1 (char 0)
Traceback (most recent call last):
  File "C:\Users\trevo\OneDrive\Desktop\twittertest\twittertest\main.py", line 31, in <module>
    main()
  File "C:\Users\trevo\OneDrive\Desktop\twittertest\twittertest\main.py", line 25, in main
    search(
  File "C:\Users\trevo\OneDrive\Desktop\twittertest\.venv\lib\site-packages\twitter\search.py", line 47, in search
    return asyncio.run(process(args, search_config, out_path))
  File "C:\Users\trevo\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Users\trevo\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 649, in run_until_complete
    return future.result()
  File "C:\Users\trevo\OneDrive\Desktop\twittertest\.venv\lib\site-packages\twitter\search.py", line 53, in process
    return await asyncio.gather(*(paginate(q, s, config, out) for q in queries))
  File "C:\Users\trevo\OneDrive\Desktop\twittertest\.venv\lib\site-packages\twitter\search.py", line 67, in paginate
    (out / f'raw/{time.time_ns()}.json').write_text(orjson.dumps(data, option=orjson.OPT_INDENT_2).decode())
  File "C:\Users\trevo\AppData\Local\Programs\Python\Python310\lib\pathlib.py", line 1155, in write_text
    return f.write(data)
  File "C:\Users\trevo\AppData\Local\Programs\Python\Python310\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f3e1' in position 284: character maps to <undefined>

Process finished with exit code 1

How does reply_to=123 work?

It appears that i don't really understand how the reply_to parameter for a tweet can be used.

I used it like:

account.tweet(msg,reply_to = ele[0])

Where msg is a string and ele[o] is the id if the tweet i want to answer.
The msg string is beginning with an @name.

What am i doing wrong?

Edit: stunning work btw.

Allow search to be done only on recent tweets

Hello,

Right now, when you are using the Search function, you retrieve every tabs of the search (trending, recent, user, media, video).
Is it possible to retrieve only one category? For example, i'd be interested in only retrieve result from the "Recent" tab, would it be possible?
After checking a little bit in the request done when using twitter, it seems that it can be done by adding the tweet_search_mode: live when requesting the search api endpoint.

Login doesn't need Email

email, username, password = '', '', ''
account = Account(username, password)
account.tweet('test 123')

This does work but if I included email it will get:
line 4, in
account = Account('' , '', '')
TypeError: Account.init() takes 3 positional arguments but 4 were given

Debug Options

In the examples provided in the readme, there's two different debug values.
These are not elaborated on what the difference is.
Is debug 1 just for scrapers and debug 2 just for regular account stuff?
Do the debug options give different amounts of info?
Is it possible to parse specific parts of the debug info to not clog up the command line?

Search does not work

https://github.com/huksley/tw-webapp

from twitter.search import search
r = search('Elon Musk')
print(r)
Goes forever

2023-04-15 15:34:05,639.639 DEBUG: Elon Musk
2023-04-15 15:34:07,827.827 DEBUG: Elon Musk
2023-04-15 15:34:10,117.117 DEBUG: Elon Musk
2023-04-15 15:34:12,189.189 DEBUG: Elon Musk
2023-04-15 15:34:14,499.499 DEBUG: Elon Musk
2023-04-15 15:34:16,616.616 DEBUG: Elon Musk
2023-04-15 15:34:18,427.427 DEBUG: Elon Musk
2023-04-15 15:34:20,573.573 DEBUG: Elon Musk
2023-04-15 15:34:22,515.515 DEBUG: Elon Musk
2023-04-15 15:34:24,345.345 DEBUG: Elon Musk
2023-04-15 15:34:26,184.184 DEBUG: Elon Musk
2023-04-15 15:34:27,861.861 DEBUG: Elon Musk
2023-04-15 15:34:29,676.676 DEBUG: Elon Musk
2023-04-15 15:34:31,490.490 DEBUG: Elon Musk
2023-04-15 15:34:33,226.226 DEBUG: Elon Musk
2023-04-15 15:34:34,426.426 DEBUG: Elon Musk
2023-04-15 15:34:35,464.464 DEBUG: Elon Musk
2023-04-15 15:34:36,327.327 DEBUG: No data for: Elon Musk | retrying in 1.05 seconds		
2023-04-15 15:34:38,438.438 DEBUG: Elon Musk
2023-04-15 15:34:39,322.322 DEBUG: No data for: Elon Musk | retrying in 1.40 seconds		
2023-04-15 15:34:41,663.663 DEBUG: Elon Musk
2023-04-15 15:34:42,667.667 DEBUG: No data for: Elon Musk | retrying in 1.32 seconds		
2023-04-15 15:34:45,008.008 DEBUG: No data for: Elon Musk | retrying in 2.11 seconds		
2023-04-15 15:34:48,211.211 DEBUG: No data for: Elon Musk | retrying in 4.50 seconds		
2023-04-15 15:34:53,590.590 DEBUG: No data for: Elon Musk | retrying in 8.18 seconds		
2023-04-15 15:35:02,850.850 DEBUG: Elon Musk
2023-04-15 15:35:03,769.769 DEBUG: No data for: Elon Musk | retrying in 1.92 seconds		
2023-04-15 15:35:06,799.799 DEBUG: Elon Musk
2023-04-15 15:35:07,718.718 DEBUG: No data for: Elon Musk | retrying in 1.25 seconds		
2023-04-15 15:35:10,038.038 DEBUG: Elon Musk
2023-04-15 15:35:10,901.901 DEBUG: No data for: Elon Musk | retrying in 1.09 seconds		
2023-04-15 15:35:12,888.888 DEBUG: No data for: Elon Musk | retrying in 2.08 seconds		
2023-04-15 15:35:15,833.833 DEBUG: No data for: Elon Musk | retrying in 4.33 seconds		
2023-04-15 15:35:21,520.520 DEBUG: Elon Musk
2023-04-15 15:35:22,340.340 DEBUG: No data for: Elon Musk | retrying in 1.29 seconds		
2023-04-15 15:35:24,615.615 DEBUG: No data for: Elon Musk | retrying in 2.63 seconds		
2023-04-15 15:35:28,405.405 DEBUG: Elon Musk
2023-04-15 15:35:29,260.260 DEBUG: No data for: Elon Musk | retrying in 1.39 seconds		
2023-04-15 15:35:31,635.635 DEBUG: No data for: Elon Musk | retrying in 2.83 seconds		
2023-04-15 15:35:35,531.531 DEBUG: Elon Musk
2023-04-15 15:35:36,556.556 DEBUG: Elon Musk
2023-04-15 15:35:37,535.535 DEBUG: No data for: Elon Musk | retrying in 1.55 seconds		
2023-04-15 15:35:40,074.074 DEBUG: No data for: Elon Musk | retrying in 2.59 seconds		
2023-04-15 15:35:44,243.243 DEBUG: Elon Musk
2023-04-15 15:35:45,059.059 DEBUG: No data for: Elon Musk | retrying in 1.70 seconds		
2023-04-15 15:35:47,745.745 DEBUG: No data for: Elon Musk | retrying in 2.78 seconds		
2023-04-15 15:35:51,540.540 DEBUG: Elon Musk
2023-04-15 15:35:52,531.531 DEBUG: No data for: Elon Musk | retrying in 1.61 seconds		
2023-04-15 15:35:55,083.083 DEBUG: No data for: Elon Musk | retrying in 2.53 seconds		
2023-04-15 15:35:58,608.608 DEBUG: Elon Musk
2023-04-15 15:35:59,437.437 DEBUG: No data for: Elon Musk | retrying in 1.06 seconds		
2023-04-15 15:36:01,401.401 DEBUG: No data for: Elon Musk | retrying in 2.35 seconds		
2023-04-15 15:36:04,718.718 DEBUG: No data for: Elon Musk | retrying in 4.22 seconds		
2023-04-15 15:36:10,098.098 DEBUG: Elon Musk
2023-04-15 15:36:11,145.145 DEBUG: Elon Musk
2023-04-15 15:36:12,250.250 DEBUG: Elon Musk
2023-04-15 15:36:13,405.405 DEBUG: Elon Musk
2023-04-15 15:36:14,313.313 DEBUG: No data for: Elon Musk | retrying in 1.16 seconds		
2023-04-15 15:36:16,303.303 DEBUG: No data for: Elon Musk | retrying in 2.53 seconds		
2023-04-15 15:36:19,867.867 DEBUG: Elon Musk
2023-04-15 15:36:20,799.799 DEBUG: No data for: Elon Musk | retrying in 1.67 seconds		
2023-04-15 15:36:23,438.438 DEBUG: No data for: Elon Musk | retrying in 2.10 seconds

Interestingly ${HOME}/data/raw contains json files

Pagination info

Is there a way I can get the pagination info from the scraper requests?

The reason I ask is because I'm trying to use multiple accounts to get all the followers for a given account, without reaching the API's rate limits.

I would need to be able to start the scraping from the same pagination position where the previous account finished.

Make logging a toggle

Currently logging is enabled by default and there is no way to turn this off (as far as I can tell).
It'd be appreciated if logging could be toggled on and/or off at runtime by calling a method or setting a variable.

Use case: some other programs might want to use the STDOUT output of a python script that uses this package, but it's currently full of debug/log messages, which result in a lot of extra/unnecessary parsing.

Adding same api methods but in async

I want to use this package on my bot, and I prefer to use async method to avoid network congestion. For example, I briefly read the account.py and found that most of the methods are calling gql() which use self.session.request to make request, and the seesion is from httpx.Client(). To make it async maybe we just need to replace httpx.Client() as httpx.AsyncClient() and make other changes accordingly. It might be easy to implement other async method in the same way?

Hello

Hello,
could you help me,
is it possible to get recent tweets by search methods?
thank you

Using CLI

Hello, is there a way to use the scraper from the CLI as I'm a great noob when it come to code writing in Python? Many thanks.

support python version 3.9

Would it be possible to lower the python version requirement?

Trying to deploy an application to lambda/edge function is proving difficult as currently a lot of the major providers only support python version 3.9.

Rate limit

Hi, I hadn't used this before, but I wonder if these APIs have a small rate limit?

TypeError: __init__() got an unexpected keyword argument 'debug'

Trying to understand what i'm doing wrong here...

>>> email, username, password = '[email protected]','blah','password'
>>> account = Account(email, username, password, debug=2, save=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument 'debug'
 

Removing debug and save parameters, gives a different error

>>> account = Account(email, username, password)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() takes 3 positional arguments but 4 were given

Tweet

Hi, how can I use tweet reply_params? Can you give an example with reply_params, please?

tweet(s, 'test 123', reply_params=.....)

Home timeline access

Hi,

I've read through the README file and examples directory, but could not find a way to get the tweets from home timeline in (reverse chronological order).

Is there a way to get these tweets (only the ones from people I am following, not the ones recommended "fo you" by twitter).

Support curl-cffi

While the client currently forges a Mozilla user-agent, Python is still distinguishable from real browser requests due to its OpenSSL usage. To provide some protection against Twitter implementing TLS fingerprinting against its GraphQL API, could you add optional support for curl-cffi, a wrapper for curl-impersonate / curl-impersonate-win?

Twitter search seems broken

I think Twitter has recently changed something related to the advanced search – needs login now? With the latest commit:

In [2]: from twitter.search import search
   ...:
   ...: r = search('Elon Musk',limit=100)
   ...: print(r)
2023-04-21 06:43:29,735.735 DEBUG: 'timeline'
2023-04-21 06:43:29,736.736 DEBUG: No data for: Elon Musk | retrying in 1.71 seconds
2023-04-21 06:43:31,589.589 DEBUG: 'timeline'
2023-04-21 06:43:31,590.590 DEBUG: No data for: Elon Musk | retrying in 2.67 seconds
2023-04-21 06:43:34,392.392 DEBUG: 'timeline'
2023-04-21 06:43:34,392.392 DEBUG: No data for: Elon Musk | retrying in 4.54 seconds
2023-04-21 06:43:39,071.071 DEBUG: 'timeline'
2023-04-21 06:43:39,071.071 DEBUG: No data for: Elon Musk | retrying in 8.01 seconds
2023-04-21 06:43:47,216.216 DEBUG: 'timeline'
2023-04-21 06:43:47,216.216 DEBUG: No data for: Elon Musk | retrying in 16.75 seconds
``

Reply method doesn't work. Maybe should implement OAuth2Session.

Hello,

twitter is currently using the query_id -tr9gsjcukmYZRN4dpYN8g for reply and this query_id probably only works in oauth session. I can normally send tweets but not reply. does anyone have a solution for this? Can anyone reply with the query_id 7TKRKCPuAGsmYde0CudbVg?

Current commit: 28cd391

Output with new query_id:

[success] xxxxx login success 2023-05-07 02:10:41,856.856 DEBUG: [403] 2023-05-07 02:10:41,856.856 DEBUG: https://twitter.com/i/api/graphql/-tr9gsjcukmYZRN4dpYN8g/CreateTweet

Old query_id:

[success] xxxxx login success 2023-05-07 02:12:06,529.529 DEBUG: [403] 2023-05-07 02:12:06,529.529 DEBUG: https://twitter.com/i/api/graphql/7TKRKCPuAGsmYde0CudbVg/CreateTweet

Scraper functions not working

All scraping functions return the same error. Here is example code and the error.

code:

    scraper = Scraper('x', 'x')
    following = scraper.following([2360121187])
    print(following)

error:

  File "C:\Users\trevo\OneDrive\Desktop\twittertest\twittertest\main.py", line 22, in <module>
    main()
  File "C:\Users\trevo\OneDrive\Desktop\twittertest\twittertest\main.py", line 17, in main
    following = scraper.following([2360121187])
  File "C:\Users\trevo\OneDrive\Desktop\twittertest\.venv\lib\site-packages\twitter\scraper.py", line 65, in following
    return self.run(ids, Operation.Data.Following, limit)
  File "C:\Users\trevo\OneDrive\Desktop\twittertest\.venv\lib\site-packages\twitter\scraper.py", line 102, in run
    res = self.query(ids, operation)
  File "C:\Users\trevo\OneDrive\Desktop\twittertest\.venv\lib\site-packages\twitter\scraper.py", line 119, in query
    self.save_data(res, name)
  File "C:\Users\trevo\OneDrive\Desktop\twittertest\.venv\lib\site-packages\twitter\scraper.py", line 236, in save_data
    path = Path(f'data/raw/{d[ID]}')
TypeError: 'NoneType' object is not subscriptable
2023-04-08 16:51:23,711.711 DEBUG: failed to download (2360121187, 'https://api.twitter.com/graphql/wjvx62Hye2dGVvnvVco0xA/Following?queryId="wjvx62Hye2dGVvnvVco0xA"&variables={"userId":2360121187,"count":1000,"includePromotedContent":true,"withDownvotePerspective":false,"withReactionsMetadata":false,"withReactionsPerspective":false,"withSuperFollowsTweetFields":true,"withSuperFollowsUserFields":true}&features={"responsive_web_twitter_blue_verified_badge_is_enabled":true,"responsive_web_graphql_exclude_directive_enabled":true,"verified_phone_label_enabled":true,"responsive_web_graphql_timeline_navigation_enabled":true,"responsive_web_graphql_skip_user_profile_image_extensions_enabled":true,"tweetypie_unmention_optimization_enabled":true,"vibe_api_enabled":true,"responsive_web_edit_tweet_api_enabled":true,"graphql_is_translatable_rweb_tweet_is_translatable_enabled":true,"view_counts_everywhere_api_enabled":true,"longform_notetweets_consumption_enabled":true,"tweet_awards_web_tipping_enabled":true,"freedom_of_speech_not_reach_fetch_enabled":true,"standardized_nudges_misinfo":true,"tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled":true,"interactive_text_enabled":true,"responsive_web_text_conversations_enabled":true,"longform_notetweets_richtext_consumption_enabled":true,"responsive_web_enhance_cards_enabled":true}'): Cannot serialize non-str key None

400: Internal Server Error

2023-05-01 09:30:07,585.585 DEBUG: [�[31merror�[0m] 400
{
    "errors": [
        {
            "message": "Internal server error",
            "extensions": {
                "name": "InternalServerError",
                "source": "Server",
                "retry_after": 0,
                "code": 0,
                "kind": "Operational",
                "tracing": {"trace_id": "8d878e4f6abb553b"},
            },
            "code": 0,
            "kind": "Operational",
            "name": "InternalServerError",
            "source": "Server",
            "retry_after": 0,
            "tracing": {"trace_id": "8d878e4f6abb553b"},
        }
    ]
}

I'm unsure what to make of this error.
When having debug=1 when logging in, it throws this error at me with a 400 code and then hangs.
I couldn't find anything equivalent in Twitter's API docs.
Does this have to do with the API itself dying or my own internet cutting out?
Is there something you could add in the future to parse out when errors like these happen so it can retry again without hanging any looping program forever?

Latest=True not actually pulling latest results

I have some simple code to pull the latest tweets with a given domain. However the results saved are definitely not the latest.

from twitter.search import Search
search = Search(EMAIL, USERNAME, PASSWORD)
search.run('(viralsweep.com or swee.ps)', limit=100, latest=True)

This code returns tweets that were created in February 2022, July 2022, October 2022 but there have definitely been more tweets when I search for this query on Twitter.com

Am I doing something wrong? Could it be the code?

Clarify usage of scrapers/official APIs in this package

Hi, I'm interested in using this package in my project. However, I'm not sure what rate limits there are for the search endpoint. Does it rely on an API that might become commercial or already is subjected to rate limits, or is it implemented through a scraper? It would be great to document this in the readme. Thanks in advance!

Using with multiple accounts

Hello, thanks for wonderful library,

my specific usecase involves extracting every single follower or following, but
with single account the GraphQL API limit is exceeded very quickly (50/15 min. for followers, 500/15min. for
followings). I therefore need to implement some kind of multi-acc support, so my questions would be:

  1. Is there any way to achieve this right now by using this library and if not are there any plans
    to add multi-account support with HTTP proxies support as using multi accounts on single IP is almost
    certain ban?

  2. Cursor support. Are there any plans? I need to pickup extracting followers/followings from where previous
    account finished if rate limit is reached.

  3. Is there a way to get remaining limits with this library?

Search keeps retrying when there's no data left to scrape

Hi! Thank you for your work, it's helping me so much! I found an issue that is annoying me recently:

Searching for astrophysics since:2023-04-01 until:2023-04-02 with only 50 tweets:

>>> latest_results = search.run(
...     'astrophysics since:2023-04-01 until:2023-04-02',
...     limit=50,
... )
2023-05-04 15:59:47,016.016 DEBUG: astrophysics since:2023-04-01 until:2023-04-02
2023-05-04 15:59:48,164.164 DEBUG: astrophysics since:2023-04-01 until:2023-04-02
2023-05-04 15:59:49,244.244 DEBUG: [success] returned 66 search results for astrophysics since:2023-04-01 until:2023-04-02

Now searching for astrophysics since:2023-04-01 until:2023-04-02 with 200 tweets:

>>> latest_results = search.run(
...     'astrophysics since:2023-04-01 until:2023-04-02',
...     limit=200,
... )
2023-05-04 15:54:43,028.028 DEBUG: astrophysics since:2023-04-01 until:2023-04-02
2023-05-04 15:54:44,178.178 DEBUG: astrophysics since:2023-04-01 until:2023-04-02
2023-05-04 15:54:45,508.508 DEBUG: astrophysics since:2023-04-01 until:2023-04-02
2023-05-04 15:54:46,758.758 DEBUG: astrophysics since:2023-04-01 until:2023-04-02
2023-05-04 15:54:47,883.883 DEBUG: astrophysics since:2023-04-01 until:2023-04-02
2023-05-04 15:54:49,059.059 DEBUG: astrophysics since:2023-04-01 until:2023-04-02
2023-05-04 15:54:50,067.067 DEBUG: astrophysics since:2023-04-01 until:2023-04-02
2023-05-04 15:54:50,733.733 DEBUG: astrophysics since:2023-04-01 until:2023-04-02
2023-05-04 15:54:51,159.159 DEBUG: No data for: astrophysics since:2023-04-01 until:2023-04-02 | retrying in 1.45 seconds
2023-05-04 15:54:53,052.052 DEBUG: No data for: astrophysics since:2023-04-01 until:2023-04-02 | retrying in 2.13 seconds
2023-05-04 15:54:55,555.555 DEBUG: No data for: astrophysics since:2023-04-01 until:2023-04-02 | retrying in 4.80 seconds
(Retries almost lasts forever)
... 

The expected behavior for me, when data ends, should be ending the search with only the data that was able to be scraped (let's say that it was 100 tweets).

Other possible error is that the account is being temporarily suspended of searching because of request limits, but I don't think that this is the case. (That's why I chose a low-key topic in a very short date range)

What I think it should be done:

  • Differenciate whether the account is suspended of searching or there's no data left to scrape
  • If there's no data left to scrape, stop the search there instead of retrying
  • Limit the retry interval to a more reasonable one (like only 4 retries) or possibly make it so we can choose how many retries we want

Proxy

Hi, is it possible to login and post tweets over proxy?

Account functions not working

I've now tested every function in every module (account, scraper, search) using multiple accounts, and multiple vpns/no vpn. None of the codebase works for me. Any ideas?
code:

from twitter.account import Account
    account = Account('myuser', 'mypass')
    account.tweet('hello')

error:

[SUCCESS] myuser logged in successfully
2023-04-08 17:08:53,204.204 DEBUG: FAILED to combine search results, input length is 0: line 1 column 1 (char 0)

Auth error on all accounts

Hi! I'm facing an issue when trying to use the scraper. An account I used succesfully several times today has stopped working, and so did other 2 accounts I tried. I even logged in on those accounts normally through Twitter's web client, so it doesn't seem like they have been blocked.

The error message I'm receiveing when trying to instantiate an Scraper object is (I changed my actual e-mail for '[email protected]' for privacy):

'flow_token'
[error] failed to update token at flow_duplication_check
'flow_token'
[error] [email protected] login failed
2023-05-02 14:52:48,524.524 DEBUG: [error] 200 {'errors': [{'message': 'Authorization: Denied by access control: unspecified reason', 'locations': [{'line': 7, 'column': 11}], 'path': ['user', 'result', 'timeline', 'timeline'], 'extensions': {'name': 'AuthorizationError', 'source': 'Client', 'code': 37, 'kind': 'Permissions', 'tracing': {'trace_id': 'd50ba310715d015f'}}, 'code': 37, 'kind': 'Permissions', 'name': 'AuthorizationError', 'source': 'Client', 'tracing': {'trace_id': 'd50ba310715d015f'}}], 'data': {'user': {'result': {'__typename': 'User', 'timeline': {}}}}}```

Not Understanding Some Things

Hi,

My personal objective is to access my personal Liked Tweet list, and download said Tweets.

I have a few questions:

  • In email, username, password = ..., ..., ..., am I supposed to fill in my information in string formats, like so?
    email, username, password = '[email protected]', 'JohnDoe', 'JohnDoe123' ?

  • scraper = Scraper(email, username, password, debug=1, save=True) gives me the error __init__() got an unexpected keyword argument 'debug'. Is scraper = Scraper(username, password) the intended format?

  • For something like likes = scraper.likes([123, 234, 345]), am I supposed to insert my Twitter ID in that list? When I did so, I got the following error, TypeError 'NoneType' object is not subscriptable

If there's any documentation available, I would love to see it. Thank you.

Async Error

When i use this method

followers = scraper.followers([USER_ID])

for me happens this error:
image

how fix it?

Is email required?

Hey,

For of all, thanks for the library, it's working perfectly.
I have one question, recently you've added the "email" parameter to the Scraper and it's also one of the parameter in the Account class.
Is it required if I have a username parameter setted when building either of those?

When logging to twitter from webpage, you can either use an email or a username to connect.
If I don't specify one, some features won't work?

Thanks!

Update usage samples/pip

The samples in the readme seem not to match the pip package.

Some examples:

>>> account = Account(email, username, password, debug=2, save=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Account.__init__() got an unexpected keyword argument 'debug'

>>> scraper = Scraper(email, username, password, debug=1, save=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Scraper.__init__() got an unexpected keyword argument 'debug'

>>> from twitter.search import Search
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'Search' from 'twitter.search' (/usr/local/lib/python3.10/dist-packages/twitter/search.py)

If I install the package from the latest revision of this repo, the examples (technically) work, however! So maybe there should also just be any note that the pip package is not always up to date. 😅

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.