Search code examples
pythonjsontwitter

Determine If a Tweet is a Retweet or Not


I am trying to find whether a certain tweet is an original tweet or a retweet.

I tried using retweeted_status, but it does not appear in the JSON even that the status is a retweet.


Solution

  • If the tweet is a retweet, then the value of retweeted_status will contain the JSON object of the original tweet.

    From the Twitter API Documentation:

    If you are working with a Retweet object, then that object will contain two Tweet objects, complete with two User objects. The Tweet that was Retweeted is referred to as the 'original' Tweet and is displayed under the 'retweeted_status' key.

    Also from here:

    Retweets can be distinguished from typical Tweets by the existence of a retweeted_status attribute. This attribute contains a representation of the original Tweet that was retweeted.

    Example (copied from the pages above) of original tweet JSON object skeleton (does not have a retweeted_status key):

    {
      "tweet": {
        "user": {
          ...
        },
        "place": {
          ...
        },
        "entities": {
          ...
        },
        "extended_entities": {
          ...
        }
      }
    }
    

    Example of a Retweet JSON object skeleton (has the retweeted_status key):

    {
      "tweet": {
        "user": {
    
        },
        "retweeted_status": {
          "tweet": {
            "user": {
    
            },
            "place": {
    
            },
            "entities": {
    
            },
            "extended_entities": {
    
            }
          },
    
        },
        "place": {
    
        },
        "entities": {
    
        },
        "extended_entities": {
    
        }
      }
    }