How to GET Tweets from a single user?


#1

I’m new to both twurl and the Premium API, so thanks in advance for any patience as I figure this is a beginner’s question.

I’m looking for a twul query that will just GET the Tweets of a single user. Seems like a pretty expected use case.

However I’m running the following twurl, and I would expect it to only return Tweets made by (eg: from) one specific user (in this case, ‘realDonaldTrump’). However it appears to be returning messages he didn’t write - perhaps Tweets which mention the queried user name. Is this working as intended?

Thanks!

twurl '/1.1/search/tweets.json?q=from%3ArealDonaldTrump' | jq .

https://twitter.com/search?q=from%3ArealDonaldTrump

`


#2

Hi @TCSF.

What you used was the Search Tweets API, but what you wanted to use is the Get Tweet timelines API.

twurl ‘/1.1/search/tweets.json?q=from%3ArealDonaldTrump’ | jq

This request that you sent then sent back a response of Tweets that contained the specified query “realDonaldTrump”. These Tweets are not from one specific user, they are from any user that had “realDonaldTrump” within the Tweet, thus the mentions, RTs and Tweets not from Trump himself.

To search Tweets of a user timeline, what you want to do is use the GET statuses/user_timeline reference and add any of the available parameters that you want.

Here is an example request using twurl

twurl GET -H api.twitter.com “/1.1/statuses/user_timeline.json?screen_name=realDonaldTrump&count=3&exclude_replies=true&include_rts=false” | jq

I used the screen_name, count, exclude_replies, and include_rts parameters so that the response will only give back three organic Tweets from Donald Trump.

Here is the response

[
  {
    "created_at": "Sat Apr 07 17:35:28 +0000 2018",
    "id": 982673223719489500,
    "id_str": "982673223719489536",
    "text": "Just spoke to @JustinTrudeau to pay my highest respect and condolences to the families of the terrible Humboldt Tea… https://t.co/C9UPsBZvb1",
    "truncated": true,
    "entities": {
      "hashtags": [],
      "symbols": [],
      "user_mentions": [
        {
          "screen_name": "JustinTrudeau",
          "name": "Justin Trudeau",
          "id": 14260960,
          "id_str": "14260960",
          "indices": [
            14,
            28
          ]
        }
      ],
      "urls": [
        {
          "url": "https://t.co/C9UPsBZvb1",
          "expanded_url": "https://twitter.com/i/web/status/982673223719489536",
          "display_url": "twitter.com/i/web/status/9…",
          "indices": [
            117,
            140
          ]
        }
      ]
    },
    "source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>",
    "in_reply_to_status_id": null,
    "in_reply_to_status_id_str": null,
    "in_reply_to_user_id": null,
    "in_reply_to_user_id_str": null,
    "in_reply_to_screen_name": null,
    "user": {
      "id": 25073877,
      "id_str": "25073877",
      "name": "Donald J. Trump",
      "screen_name": "realDonaldTrump",
      "location": "Washington, DC",
      "description": "45th President of the United States of America🇺🇸",
      "url": "https://t.co/OMxB0x7xC5",
      "entities": {
        "url": {
          "urls": [
            {
              "url": "https://t.co/OMxB0x7xC5",
              "expanded_url": "http://www.Instagram.com/realDonaldTrump",
              "display_url": "Instagram.com/realDonaldTrump",
              "indices": [
                0,
                23
              ]
            }
          ]
        },
        "description": {
          "urls": []
        }
      },
      "protected": false,
      "followers_count": 50058927,
      "friends_count": 45,
      "listed_count": 85945,
      "created_at": "Wed Mar 18 13:46:38 +0000 2009",
      "favourites_count": 24,
      "utc_offset": -14400,
      "time_zone": "Eastern Time (US & Canada)",
      "geo_enabled": true,
      "verified": true,
      "statuses_count": 37248,
      "lang": "en",
      "contributors_enabled": false,
      "is_translator": false,
      "is_translation_enabled": true,
      "profile_background_color": "6D5C18",
      "profile_background_image_url": "http://pbs.twimg.com/profile_background_images/530021613/trump_scotland__43_of_70_cc.jpg",
      "profile_background_image_url_https": "https://pbs.twimg.com/profile_background_images/530021613/trump_scotland__43_of_70_cc.jpg",
      "profile_background_tile": true,
      "profile_image_url": "http://pbs.twimg.com/profile_images/874276197357596672/kUuht00m_normal.jpg",
      "profile_image_url_https": "https://pbs.twimg.com/profile_images/874276197357596672/kUuht00m_normal.jpg",
      "profile_banner_url": "https://pbs.twimg.com/profile_banners/25073877/1521874230",
      "profile_link_color": "1B95E0",
      "profile_sidebar_border_color": "BDDCAD",
      "profile_sidebar_fill_color": "C5CEC0",
      "profile_text_color": "333333",
      "profile_use_background_image": true,
      "has_extended_profile": false,
      "default_profile": false,
      "default_profile_image": false,
      "following": true,
      "follow_request_sent": false,
      "notifications": false,
      "translator_type": "regular"
    },
    "geo": null,
    "coordinates": null,
    "place": null,
    "contributors": null,
    "is_quote_status": false,
    "retweet_count": 3437,
    "favorite_count": 15381,
    "favorited": false,
    "retweeted": false,
    "lang": "en"
  },
  {
    "created_at": "Fri Apr 06 20:26:53 +0000 2018",
    "id": 982353975595929600,
    "id_str": "982353975595929600",
    "text": "Congratulations to @bernieandsid on their new @77wabcradio morning radio show in New York City. It was an honor to… https://t.co/6qhLQPgxwl",
    "truncated": true,
    "entities": {
      "hashtags": [],
      "symbols": [],
      "user_mentions": [
        {
          "screen_name": "bernieandsid",
          "name": "Bernie & Sid in the Morning",
          "id": 4857446475,
          "id_str": "4857446475",
          "indices": [
            19,
            32
          ]
        },
        {
          "screen_name": "77WABCradio",
          "name": "77 WABC Radio",
          "id": 104567779,
          "id_str": "104567779",
          "indices": [
            46,
            58
          ]
        }
      ],
      "urls": [
        {
          "url": "https://t.co/6qhLQPgxwl",
          "expanded_url": "https://twitter.com/i/web/status/982353975595929600",
          "display_url": "twitter.com/i/web/status/9…",
          "indices": [
            116,
            139
          ]
        }
      ]
    },
    "source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>",
    "in_reply_to_status_id": null,
    "in_reply_to_status_id_str": null,
    "in_reply_to_user_id": null,
    "in_reply_to_user_id_str": null,
    "in_reply_to_screen_name": null,
    "user": {
      "id": 25073877,
      "id_str": "25073877",
      "name": "Donald J. Trump",
      "screen_name": "realDonaldTrump",
      "location": "Washington, DC",
      "description": "45th President of the United States of America🇺🇸",
      "url": "https://t.co/OMxB0x7xC5",
      "entities": {
        "url": {
          "urls": [
            {
              "url": "https://t.co/OMxB0x7xC5",
              "expanded_url": "http://www.Instagram.com/realDonaldTrump",
              "display_url": "Instagram.com/realDonaldTrump",
              "indices": [
                0,
                23
              ]
            }
          ]
        },
        "description": {
          "urls": []
        }
      },
      "protected": false,
      "followers_count": 50058927,
      "friends_count": 45,
      "listed_count": 85945,
      "created_at": "Wed Mar 18 13:46:38 +0000 2009",
      "favourites_count": 24,
      "utc_offset": -14400,
      "time_zone": "Eastern Time (US & Canada)",
      "geo_enabled": true,
      "verified": true,
      "statuses_count": 37248,
      "lang": "en",
      "contributors_enabled": false,
      "is_translator": false,
      "is_translation_enabled": true,
      "profile_background_color": "6D5C18",
      "profile_background_image_url": "http://pbs.twimg.com/profile_background_images/530021613/trump_scotland__43_of_70_cc.jpg",
      "profile_background_image_url_https": "https://pbs.twimg.com/profile_background_images/530021613/trump_scotland__43_of_70_cc.jpg",
      "profile_background_tile": true,
      "profile_image_url": "http://pbs.twimg.com/profile_images/874276197357596672/kUuht00m_normal.jpg",
      "profile_image_url_https": "https://pbs.twimg.com/profile_images/874276197357596672/kUuht00m_normal.jpg",
      "profile_banner_url": "https://pbs.twimg.com/profile_banners/25073877/1521874230",
      "profile_link_color": "1B95E0",
      "profile_sidebar_border_color": "BDDCAD",
      "profile_sidebar_fill_color": "C5CEC0",
      "profile_text_color": "333333",
      "profile_use_background_image": true,
      "has_extended_profile": false,
      "default_profile": false,
      "default_profile_image": false,
      "following": true,
      "follow_request_sent": false,
      "notifications": false,
      "translator_type": "regular"
    },
    "geo": null,
    "coordinates": null,
    "place": null,
    "contributors": null,
    "is_quote_status": true,
    "quoted_status_id": 982267454880559100,
    "quoted_status_id_str": "982267454880559118",
    "quoted_status": {
      "created_at": "Fri Apr 06 14:43:05 +0000 2018",
      "id": 982267454880559100,
      "id_str": "982267454880559118",
      "text": "#Trump and @bernieandsid !\nWhat do you mean you missed it? You were listening to what? Oh man, well experience it a… https://t.co/JmrPCvlvAz",
      "truncated": true,
      "entities": {
        "hashtags": [
          {
            "text": "Trump",
            "indices": [
              0,
              6
            ]
          }
        ],
        "symbols": [],
        "user_mentions": [
          {
            "screen_name": "bernieandsid",
            "name": "Bernie & Sid in the Morning",
            "id": 4857446475,
            "id_str": "4857446475",
            "indices": [
              11,
              24
            ]
          }
        ],
        "urls": [
          {
            "url": "https://t.co/JmrPCvlvAz",
            "expanded_url": "https://twitter.com/i/web/status/982267454880559118",
            "display_url": "twitter.com/i/web/status/9…",
            "indices": [
              117,
              140
            ]
          }
        ]
      },
      "source": "<a href=\"https://about.twitter.com/products/tweetdeck\" rel=\"nofollow\">TweetDeck</a>",
      "in_reply_to_status_id": null,
      "in_reply_to_status_id_str": null,
      "in_reply_to_user_id": null,
      "in_reply_to_user_id_str": null,
      "in_reply_to_screen_name": null,
      "user": {
        "id": 104567779,
        "id_str": "104567779",
        "name": "77 WABC Radio",
        "screen_name": "77WABCradio",
        "location": "New York, NY",
        "description": "77 WABC Radio - New York. Where New York Comes to Talk",
        "url": "https://t.co/bUve2ZsNNf",
        "entities": {
          "url": {
            "urls": [
              {
                "url": "https://t.co/bUve2ZsNNf",
                "expanded_url": "http://www.wabcradio.com",
                "display_url": "wabcradio.com",
                "indices": [
                  0,
                  23
                ]
              }
            ]
          },
          "description": {
            "urls": []
          }
        },
        "protected": false,
        "followers_count": 9447,
        "friends_count": 347,
        "listed_count": 334,
        "created_at": "Wed Jan 13 18:40:31 +0000 2010",
        "favourites_count": 1457,
        "utc_offset": -14400,
        "time_zone": "Eastern Time (US & Canada)",
        "geo_enabled": true,
        "verified": true,
        "statuses_count": 23718,
        "lang": "en",
        "contributors_enabled": false,
        "is_translator": false,
        "is_translation_enabled": false,
        "profile_background_color": "000000",
        "profile_background_image_url": "http://pbs.twimg.com/profile_background_images/118483667/77wabctwitter_copy.jpg",
        "profile_background_image_url_https": "https://pbs.twimg.com/profile_background_images/118483667/77wabctwitter_copy.jpg",
        "profile_background_tile": true,
        "profile_image_url": "http://pbs.twimg.com/profile_images/1039757713/wabc_normal.jpg",
        "profile_image_url_https": "https://pbs.twimg.com/profile_images/1039757713/wabc_normal.jpg",
        "profile_banner_url": "https://pbs.twimg.com/profile_banners/104567779/1441114988",
        "profile_link_color": "009999",
        "profile_sidebar_border_color": "EEEEEE",
        "profile_sidebar_fill_color": "EFEFEF",
        "profile_text_color": "333333",
        "profile_use_background_image": true,
        "has_extended_profile": false,
        "default_profile": false,
        "default_profile_image": false,
        "following": false,
        "follow_request_sent": false,
        "notifications": false,
        "translator_type": "none"
      },
      "geo": null,
      "coordinates": null,
      "place": null,
      "contributors": null,
      "is_quote_status": false,
      "retweet_count": 362,
      "favorite_count": 818,
      "favorited": false,
      "retweeted": false,
      "possibly_sensitive": false,
      "lang": "en"
    },
    "retweet_count": 6790,
    "favorite_count": 29398,
    "favorited": false,
    "retweeted": false,
    "possibly_sensitive": false,
    "lang": "en"
  },
  {
    "created_at": "Fri Apr 06 20:23:58 +0000 2018",
    "id": 982353242196766700,
    "id_str": "982353242196766720",
    "text": "“BET founder: Trump's economy is bringing black workers back into the labor force” https://t.co/TtMDfi4bv0",
    "truncated": false,
    "entities": {
      "hashtags": [],
      "symbols": [],
      "user_mentions": [],
      "urls": [
        {
          "url": "https://t.co/TtMDfi4bv0",
          "expanded_url": "https://www.cnbc.com/2018/04/06/bet-founder-trump-economy-brings-black-workers-back-into-labor-force.html",
          "display_url": "cnbc.com/2018/04/06/bet…",
          "indices": [
            83,
            106
          ]
        }
      ]
    },
    "source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>",
    "in_reply_to_status_id": null,
    "in_reply_to_status_id_str": null,
    "in_reply_to_user_id": null,
    "in_reply_to_user_id_str": null,
    "in_reply_to_screen_name": null,
    "user": {
      "id": 25073877,
      "id_str": "25073877",
      "name": "Donald J. Trump",
      "screen_name": "realDonaldTrump",
      "location": "Washington, DC",
      "description": "45th President of the United States of America🇺🇸",
      "url": "https://t.co/OMxB0x7xC5",
      "entities": {
        "url": {
          "urls": [
            {
              "url": "https://t.co/OMxB0x7xC5",
              "expanded_url": "http://www.Instagram.com/realDonaldTrump",
              "display_url": "Instagram.com/realDonaldTrump",
              "indices": [
                0,
                23
              ]
            }
          ]
        },
        "description": {
          "urls": []
        }
      },
      "protected": false,
      "followers_count": 50058927,
      "friends_count": 45,
      "listed_count": 85945,
      "created_at": "Wed Mar 18 13:46:38 +0000 2009",
      "favourites_count": 24,
      "utc_offset": -14400,
      "time_zone": "Eastern Time (US & Canada)",
      "geo_enabled": true,
      "verified": true,
      "statuses_count": 37248,
      "lang": "en",
      "contributors_enabled": false,
      "is_translator": false,
      "is_translation_enabled": true,
      "profile_background_color": "6D5C18",
      "profile_background_image_url": "http://pbs.twimg.com/profile_background_images/530021613/trump_scotland__43_of_70_cc.jpg",
      "profile_background_image_url_https": "https://pbs.twimg.com/profile_background_images/530021613/trump_scotland__43_of_70_cc.jpg",
      "profile_background_tile": true,
      "profile_image_url": "http://pbs.twimg.com/profile_images/874276197357596672/kUuht00m_normal.jpg",
      "profile_image_url_https": "https://pbs.twimg.com/profile_images/874276197357596672/kUuht00m_normal.jpg",
      "profile_banner_url": "https://pbs.twimg.com/profile_banners/25073877/1521874230",
      "profile_link_color": "1B95E0",
      "profile_sidebar_border_color": "BDDCAD",
      "profile_sidebar_fill_color": "C5CEC0",
      "profile_text_color": "333333",
      "profile_use_background_image": true,
      "has_extended_profile": false,
      "default_profile": false,
      "default_profile_image": false,
      "following": true,
      "follow_request_sent": false,
      "notifications": false,
      "translator_type": "regular"
    },
    "geo": null,
    "coordinates": null,
    "place": null,
    "contributors": null,
    "is_quote_status": false,
    "retweet_count": 22196,
    "favorite_count": 73139,
    "favorited": false,
    "retweeted": false,
    "possibly_sensitive": false,
    "lang": "en"
  }
]

Hope this helps!

Sam