How to extract the historical tweets from twitter API? [closed]

2024/11/8 4:44:06

We need the historical tweets for some movies. Right now, we tried the streaming API and search API from twitter. The streaming API could not give us a parameter to choose the time range we need and the search API could only give us data one or two weeks in advance. Is there a way for us to extract the historical tweets from 2014-05-01 to 2014-07-01 (For example)? I found the following ways that is possible to do that:

  1. Twitter advanced search https://twitter.com/search-advanced?lang=en It could find the search result I need. But how could I download the search result? Is there anyway to write a code and save the search result?

  2. Using the twitter analytic web site like topsy. But it also has the difficulty to save the result.

  3. It seems that some packages like twitter4J could help with that: http://twitter4j.org/en/code-examples.html Is there any python or R package could help us to do that?

  4. We need this data to do a research. It is not a good choice to spend a long time for the extraction of the data. Is there anyway to buy this data from some professional web site?

Answer

You can use the following library https://github.com/Jefferson-Henrique/GetOldTweets-python to get old tweets in Twitter.

Make GetOldTweets-python as the current directory in Python using

 cd GetOldTweets-python

then do the following

In Python,

import got
tweetCriteria = got.manager.TweetCriteria().setQuerySearch('search_term').setSince("2014-05-01").setUntil("2014-07-01").setMaxTweets(10000)
tweet = got.manager.TweetManager.getTweets(tweetCriteria)[0]print tweet.text

In terminal,

python Exporter.py --querysearch 'search_term' --since 2014-05-01 --until 2014-07-01 --maxtweets 10000

Replace 'search_term' with the search term.

https://en.xdnf.cn/q/120655.html

Related Q&A

ValueError: invalid literal for int() with base 16: [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

Modify list in Python [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable…

How to delete files inside hidden folder with python? [duplicate]

This question already has answers here:How can I delete a file or folder in Python?(18 answers)Closed 5 years ago.I want do delete a file, for ex. myfile.txt that is stored under a hidden folder. Is i…

Matching keywords in a dictionary to a list in Python

The following dictionary gives the word and its value:keywords = {alone: 1, amazed: 10, amazing: 10, bad: 1, best: 10, better: 7, excellent: 10, excited: 10, excite: 10}Following the dictionary are two…

How to make case insensitive? [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

Webpage data extraction automation using python and selenium webdriver [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

Asking the user if they want to play again [duplicate]

This question already has answers here:Ask the user if they want to repeat the same task again(2 answers)Closed 5 years ago.Basically its a guessing game and I have literally all the code except for th…

IF statement (checking for a string in a list) behave weirdly [duplicate]

This question already has answers here:How to test multiple variables for equality against a single value?(31 answers)Closed 10 years ago.This will probably be a dumb question, but why does this piece…

filteration in txt file in python

I have too many lines like this:>ENSG00000100206|ENST00000216024|DMC1|2371|38568257;38570043|38568289;38570286 CTCAGACGTCGGGCCGACGCAAGGCCACGCGCGCGAACACACAGGTGCGGCCCCGGGCCA CACGCACACCGTACAC >ENSG0…

Count the number of times elements in a numpy array consecutively satisfy a condition

I have a numpy array as follows:import numpy as np a = np.array([1, 4, 2, 6, 4, 4, 6, 2, 7, 6, 2, 8, 9, 3, 6, 3, 4, 4, 5, 8])and a constant number b=6I am searching for a number c which is defined by t…