I want to extract Japanese tweet text using the tweet API. Are there some sample code about this problem?
I just want extract Japanese tweets that are not using a keyword.
I want to extract Japanese tweet text using the tweet API. Are there some sample code about this problem?
I just want extract Japanese tweets that are not using a keyword.
You can add 'lang' key when you make a query to restrict the language.
According to the document, it says "Restricts tweets to the given language, given by an ISO 639-1 code. Language detection is best-effort."
It leads to something like this:
import json
from requests_oauthlib import OAuth1Session
tw = OAuth1Session("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET")
url = "https://api.twitter.com/1.1/search/tweets.json"
params = {'q' : "keyword", 'count' : 100, 'lang' : 'ja'}
while True:
req = tw.get(url, params=params)
if req.status_code == 200:
tweets = json.loads(req.text)
for tweet in tweets['statuses']:
print(tweet['text'])
print("<<<<<<<<<<<<<<<<<<<")