twintproject / twint

An advanced Twitter scraping & OSINT tool written in Python that doesn't use Twitter's API, allowing you to scrape a user's followers, following, Tweets and more while evading most API limitations.
MIT License
15.77k stars 2.73k forks source link

[Question] RefreshTokenException encountered - no longer have access to tweets #1149

Open MarkPadley opened 3 years ago

MarkPadley commented 3 years ago

After approximately fifteen minutes of joy looking at tweets successfully within Jupyter, I then reran a cell which had executed fully a few minutes earlier...

Command Ran

c = twint.Config() c.Username = "noneprivacy"

c.Search = "covid"

Run

twint.run.Search(c)

Error as follows...

RefreshTokenException Traceback (most recent call last)

in 6 7 # Run ----> 8 twint.run.Search(c) c:\users\mark padley\src\twint\twint\run.py in Search(config, callback) 408 config.Followers = False 409 config.Profile = False --> 410 run(config, callback) 411 if config.Pandas_au: 412 storage.panda._autoget("tweet") c:\users\mark padley\src\twint\twint\run.py in run(config, callback) 327 raise 328 --> 329 get_event_loop().run_until_complete(Twint(config).main(callback)) 330 331 c:\users\mark padley\src\twint\twint\run.py in __init__(self, config) 34 # USAGE : to get a new guest token simply do `self.token.refresh()` 35 self.token = token.Token(config) ---> 36 self.token.refresh() 37 self.conn = db.Conn(config.Database) 38 self.d = datelock.Set(self.config.Until, self.config.Since) c:\users\mark padley\src\twint\twint\token.py in refresh(self) 67 else: 68 self.config.Guest_token = None ---> 69 raise RefreshTokenException('Could not find the Guest token in HTML') RefreshTokenException: Could not find the Guest token in HTML ### Environment Details Windows 10, Python 3.8.8, Jupyter notebook which was started within Ananconda. I am guessing that the lack of the refresh token causes twitter to effectively eject me from the site. It is as though twitter gets to recognise my IP address after a while, but I am running anti-virus software which gives me a VPN! I have tried restarting Anaconda and restarting the computer to no avail. Please help as this excellent 'twint' package will really help my research.
dpakpdl commented 3 years ago

Please use the proxy servers with rotating proxies so that twitter does not block your IPs. Twint does not support proxy usage. I have a workaround for this. Check it

MarkPadley commented 3 years ago

Thanks Deepak - I have incorporated these changes into my installation inside the twint directory and the token.py file using my text editor. This I then saved and ran my code again. Sadly I still am getting the same error! Is there something else I am missing?

MarkPadley commented 3 years ago

I have had a look at the 'config' file and it includes the following concerning proxies... Proxy_host: str = "" Proxy_port: int = 0 Proxy_type: object = None Do I need to make any changes here also?

dpakpdl commented 3 years ago

Did you provide the proxy host, port and type in Config?

dpakpdl commented 3 years ago

This is the example usage for it.

import twint
config = twint.Config()
config.Proxy_host = "51.158.68.68"
config.Proxy_port = "8761"
config.Proxy_type = "http"
config.Username = username
twint.run.Lookup(config)
MarkPadley commented 3 years ago

Thank you Deepak for the ongoing assistance - I input the code exactly as above - received the following ... NameError: name 'username' is not defined - could you spell out for me please exactly what I replace 'username' with?

MarkPadley commented 3 years ago

I tried commenting out the last two lines as follows...

config.Username = username

twint.run.Lookup(config)

Success!! I seem to have access to tweets again - marvellous!

MarkPadley commented 3 years ago

Further development - as soon as I select 'VPN on' I lose all access to twitter data? With VPN off no problem...?

dpakpdl commented 3 years ago

Thank you Deepak for the ongoing assistance - I input the code exactly as above - received the following ... NameError: name 'username' is not defined - could you spell out for me please exactly what I replace 'username' with?

That is the usage for user profile lookup. username is the twitter user handle.

dpakpdl commented 3 years ago

Further development - as soon as I select 'VPN on' I lose all access to twitter data? With VPN off no problem...?

That is interesting. I have not looked at the issue with VPN yet. I will let you know if I find something.

MarkPadley commented 3 years ago

Thanks Deepak - I am using Norton VPN for your information - regards, Mark