Get tweet text by IDs using twint

2.3k Views Asked by At

I have a list of tweet ids stored in a csv file, and I want to get the text content of each id, then save it with tweet ids in a csv file. This is my code but it is not working, it does not return any result.

def scrape_tweets(search_ids):
        # Configure
    
        for i in range(len(search_ids)):
            c = twint.Config()
            c.Custom["tweet"] = [search_ids[i]]
            c.Store_csv = True
            c.Output = os.path.join('../data_csv/{}.csv'.format(search_ids[i]))
            twint.run.Search(c)
        
search_ids = ['1221875106206638080','1221883443467952128'] # an example for ids list
scrape_tweets(search_ids)

I got this error when I run the code:

CRITICAL:root:twint.run:Twint:Feed:noDataExpecting value: line 1 column 1 (char 0)
sleeping for 1.0 secs
CRITICAL:root:twint.run:Twint:Feed:noDataExpecting value: line 1 column 1 (char 0)
sleeping for 8.0 secs
CRITICAL:root:twint.run:Twint:Feed:noDataExpecting value: line 1 column 1 (char 0)
sleeping for 27.0 secs
CRITICAL:root:twint.run:Twint:Feed:noDataExpecting value: line 1 column 1 (char 0)
sleeping for 64.0 secs
CRITICAL:root:twint.run:Twint:Feed:noDataExpecting value: line 1 column 1 (char 0)
1

There are 1 best solutions below

0
On

Please checkout similar issue in twint's github issue page. Apparently, twitter deleted the endpoint from which the tweets were fetched, thus the timeout. error. The solution worked for me.