Tweets from other users in premium search with from: parameter

bug

#1

I am using the premium api 30-day endpoint to search tweets from a specific user by id using Python. Most returned tweets are indeed from this user, but sometimes I also get results from other users (not retweets from searched users).

Any idea what I’m doing wrong?

My code looks like this:

		client_key = 'KEY'
		client_secret = 'SECRET

		key_secret = '{}:{}'.format(client_key, client_secret).encode('ascii')
		b64_encoded_key = base64.b64encode(key_secret)
		b64_encoded_key = b64_encoded_key.decode('ascii')


		base_url = 'https://api.twitter.com/'
		auth_url = '{}oauth2/token'.format(base_url)

		auth_headers = {
			'Authorization': 'Basic {}'.format(b64_encoded_key),
			'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
		}

		auth_data = {
			'grant_type': 'client_credentials'
		}

		auth_resp = requests.post(auth_url, headers=auth_headers, data=auth_data)
		auth_resp.json().keys()
		access_token = auth_resp.json()['access_token']
		
		search_headers = {
			'Authorization': 'Bearer {}'.format(access_token)
		}

		search_params = {
			'query': 'from:452898921 has:links',
			'maxResults': 100
		}

		search_url = '{}1.1/tweets/search/30day/prod.json'.format(base_url)

		search_resp = requests.get(search_url, headers=search_headers, params=search_params)
		tweet_data = search_resp.json()

#2

I tried your query and couldn’t get any tweets from other users that weren’t RTs - all tweets and RTs of other users came from ZetlandMagasin (id 452898921).

Incidentally, 30day calls are expensive, so remember that the normal REST user timeline https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline.html is limited to 3200 tweets, so you could use that instead for any user with less than 3200 tweets.


#3

Thanks for trying the query. I will see if I may be able to use the timeline instead of 30day.

Normally I only get tweets from the user requested, but tonight a tweet such as this appeared in the response:

        {
            "created_at": "Fri Dec 07 12:34:00 +0000 2018",
            "id": 1071019997353279488,
            "id_str": "1071019997353279488",
            "text": "RT @meme__illust: @cooler_900 くーらーさんおめでとぉぉ…!!!\nあとでなんか描かせていただきますね…私の絵ですみませんが(震え声)",
            "source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>",
            "truncated": false,
            "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": 1028237358385119233,
                "id_str": "1028237358385119233",
                "name": "くーらー",
                "screen_name": "cooler_900",
                "location": null,
                "url": "https://marshmallow-qa.com/cooler_900",
                "description": "実況者様のお絵かき垢(だ!→🍰💚/🍝/調味料)mnちゃんを主に描いてます",
                "translator_type": "none",
                "protected": false,
                "verified": false,
                "followers_count": 224,
                "friends_count": 105,
                "listed_count": 23,
                "favourites_count": 2421,
                "statuses_count": 3084,
                "created_at": "Sat Aug 11 11:11:04 +0000 2018",
                "utc_offset": null,
                "time_zone": null,
                "geo_enabled": false,
                "lang": "en",
                "contributors_enabled": false,
                "is_translator": false,
                "profile_background_color": "F5F8FA",
                "profile_background_image_url": "",
                "profile_background_image_url_https": "",
                "profile_background_tile": false,
                "profile_link_color": "1DA1F2",
                "profile_sidebar_border_color": "C0DEED",
                "profile_sidebar_fill_color": "DDEEF6",
                "profile_text_color": "333333",
                "profile_use_background_image": true,
                "profile_image_url": "http://pbs.twimg.com/profile_images/1080479150589104128/OahX7Xl1_normal.jpg",
                "profile_image_url_https": "https://pbs.twimg.com/profile_images/1080479150589104128/OahX7Xl1_normal.jpg",
                "profile_banner_url": "https://pbs.twimg.com/profile_banners/1028237358385119233/1545812164",
                "default_profile": true,
                "default_profile_image": false,
                "following": null,
                "follow_request_sent": null,
                "notifications": null
            },
            "geo": null,
            "coordinates": null,
            "place": null,
            "contributors": null,
            "retweeted_status": {
                "created_at": "Fri Dec 07 12:01:17 +0000 2018",
                "id": 1071011761686380544,
                "id_str": "1071011761686380544",
                "text": "@cooler_900 くーらーさんおめでとぉぉ…!!!\nあとでなんか描かせていただきますね…私の絵ですみませんが(震え声)",
                "source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android</a>",
                "truncated": false,
                "in_reply_to_status_id": null,
                "in_reply_to_status_id_str": null,
                "in_reply_to_user_id": 1028237358385119233,
                "in_reply_to_user_id_str": "1028237358385119233",
                "in_reply_to_screen_name": "cooler_900",
                "user": {
                    "id": 889976000930381829,
                    "id_str": "889976000930381829",
                    "name": "皐月  固定ネプリ",
                    "screen_name": "meme__illust",
                    "location": "アネモネの子守唄&神無月",
                    "url": "https://marshmallow-qa.com/meme__illust?utm_medium=url_text&utm_source=promotion",
                    "description": "ご覧のアカウントはジャンル混同雑多色々です。アイコンめっちゃ変わる■\n\n動画編集担当\n\n「メインジャンルはTRPG」\nアナログ多め落書き\nツイプロ必読▶ https://t.co/MFE3dEXN2O (更新 1/1)\n第五人格楽しいよね\nラフ&妄言垢→@Ura5satsuki5\n#皐月の1日1絵\n#皐月版ダイスワンドロ",
                    "translator_type": "none",
                    "protected": false,
                    "verified": false,
                    "followers_count": 296,
                    "friends_count": 505,
                    "listed_count": 34,
                    "favourites_count": 21318,
                    "statuses_count": 41895,
                    "created_at": "Tue Jul 25 22:29:48 +0000 2017",
                    "utc_offset": null,
                    "time_zone": null,
                    "geo_enabled": false,
                    "lang": "ja",
                    "contributors_enabled": false,
                    "is_translator": false,
                    "profile_background_color": "F5F8FA",
                    "profile_background_image_url": "",
                    "profile_background_image_url_https": "",
                    "profile_background_tile": false,
                    "profile_link_color": "1DA1F2",
                    "profile_sidebar_border_color": "C0DEED",
                    "profile_sidebar_fill_color": "DDEEF6",
                    "profile_text_color": "333333",
                    "profile_use_background_image": true,
                    "profile_image_url": "http://pbs.twimg.com/profile_images/1081296734968459264/BGfebJXT_normal.jpg",
                    "profile_image_url_https": "https://pbs.twimg.com/profile_images/1081296734968459264/BGfebJXT_normal.jpg",
                    "profile_banner_url": "https://pbs.twimg.com/profile_banners/889976000930381829/1546310576",
                    "default_profile": true,
                    "default_profile_image": false,
                    "following": null,
                    "follow_request_sent": null,
                    "notifications": null
                },
                "geo": null,
                "coordinates": null,
                "place": null,
                "contributors": null,
                "is_quote_status": false,
                "quote_count": 0,
                "reply_count": 1,
                "retweet_count": 1,
                "favorite_count": 1,
                "entities": {
                    "hashtags": [],
                    "urls": [],
                    "user_mentions": [
                        {
                            "screen_name": "cooler_900",
                            "name": "くーらー",
                            "id": 1028237358385119233,
                            "id_str": "1028237358385119233",
                            "indices": [
                                0,
                                11
                            ]
                        }
                    ],
                    "symbols": []
                },
                "favorited": false,
                "retweeted": false,
                "filter_level": "low",
                "lang": "da"
            },
            "is_quote_status": false,
            "quote_count": 0,
            "reply_count": 0,
            "retweet_count": 0,
            "favorite_count": 0,
            "entities": {
                "hashtags": [],
                "urls": [],
                "user_mentions": [
                    {
                        "screen_name": "meme__illust",
                        "name": "皐月  固定ネプリ",
                        "id": 889976000930381829,
                        "id_str": "889976000930381829",
                        "indices": [
                            3,
                            16
                        ]
                    },
                    {
                        "screen_name": "cooler_900",
                        "name": "くーらー",
                        "id": 1028237358385119233,
                        "id_str": "1028237358385119233",
                        "indices": [
                            18,
                            29
                        ]
                    }
                ],
                "symbols": []
            },
            "favorited": false,
            "retweeted": false,
            "filter_level": "low",
            "lang": "da",
            "matching_rules": [
                {
                    "tag": null
                }
            ]
        }

#4

Tried the timeline call. Unfortunately not suitable for my purposes as embedded external links are not included (e.g. tweet https://twitter.com/i/web/status/1081120367371001856 does not include https://www.zetland.dk/historie/soNVqgRb-aOZj67pz-1d505 from the embedded url in the results.


#5

The example 1071019997353279488 tweet is definitely weird - can’t explain why that would come up for that search…

As for “embedded external links are not included” - i was also surprised this didn’t work, but then noticed that it was extended tweets https://developer.twitter.com/en/docs/tweets/tweet-updates.html

So adding tweet_mode=extended parameter to the call should work, returning the embedded url:

      {
        "url": "https://t.co/g2DrDJ9jXv",
        "expanded_url": "http://www.zetland.dk/historie/soNVqgRb-aOZj67pz-1d505",
        "display_url": "zetland.dk/historie/soNVq…",
        "indices": [
          165,
          188
        ]
      }

also check out include_card_uri=true i don’t have an example but it looks relevant https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-show-id.html


#6

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.