Twitter API. Tweets containing the RT keyword on the text do not have retweeted_status attribute on the tweet object

52 Views Asked by At

I was scraping some tweets using the Twitter API. After analysing them I found out that there were no retweets on the scraped tweet objects I retrieved. That was a little bit weird and checked the text of them. It seems that a lot of them contain the RT keyword but their tweet object do not contain the "retweeted_status" attribute. This behaviour happens for old tweets, for example from 2009. I tested for newer tweet ids for example 2018 and the "retweeted_status" attribute exists. Here is my code. So is there a way to get the author of the original author of the tweet or is it a problem of the platform or of my code?

def scrape_with_requests1():

api_url = 'https://api.twitter.com/1.1/statuses/lookup.json'
headers = {
    'Authorization': f'Bearer {Bearer_TOKEN}',
    'Content-Type': 'application/json'
}

ids = "1795694173,1795892827,1795651039,1795390048,1795417154,1795658741,1795237192,1795798398,1795997608,1795878150,1795266779,1795764716,1795763059,1795765832,1795397996,1795324682,1795581091,1795493498,1795769795,1795381148,1795422875,1795730347,1795365454,1795879077,1795903792,1795082739,1795690832,1796178999,1795526103,1795702018,1795855609,1795480732,1796123661,1795617611,1795806796,1796008846,1795978977,1796100459,1795951580,1795649890,1795819695,1795812608,1795473956,1795387745,1796113863,1795367443,1795299828,1795480513,1796006603,1795455278,1795861686,1795434080,1795152055,1795163426,1796050349,1795368271,1795284685,1795556713,1795815290,1795823875,1795181226,1796164332,1796107441,1795446790,1795431762,1795772791,1795840732,1795670743,1795887828,1795996154,1796138296,1795736784,1795121866,1795539692,1795219979,1795602853,1795237495,1795896001,1795187056,1795177812,1795219221,1795871317,1795445167,1795140950,1795833196,1795363685,1795208070,1795584639,1795467867,1795126267,1795340331"
api_url += "?id=" + ids

# Send a POST request to the Twitter API for batch retrieval
try:
    response = requests.post(api_url, headers=headers)
    response.raise_for_status()  # Check for any request errors

    batch_tweet_data = response.text
    data = json.loads(batch_tweet_data)

except requests.exceptions.HTTPError as e:
    print(f"HTTP Error: {e}")
except requests.exceptions.RequestException as e:
    print(f"Request Error: {e}")
print()
0

There are 0 best solutions below