Yortw / tweetmoasharp

TweetSharp is a fast, clean wrapper around the Twitter API.
Other
72 stars 22 forks source link

No media detected in tweet that has a photo #79

Closed Aida-Enna closed 4 years ago

Aida-Enna commented 4 years ago

Before October 5, this library was working great for my needs (scraping a twitter account, grabbing the most recent non-retweeted picture and posting it on discord) - However, something broke on the 5th. Now whenever it pulls up tweets on that date or after, it says there are no Media Entities in it, even though there is a photo. Here's two tweets as an example:

https://twitter.com/PopTartADay/status/1180190327266787329 and https://twitter.com/PopTartADay/status/1180575606280462336

For both of these tweets, the same code (it hasn't been modified in months) no longer detects any Media Entities:

https://gfycat.com/AllSparseHorseshoecrab

I did notice both of these tweets have "media tags" under the picture. Could this be why? I don't really use twitter.

Thanks, and keep up the awesome work \ o /

Aida-Enna commented 4 years ago

Hello?

Yortw commented 4 years ago

Hi,

tl;dr Set the TweetMode property of the TwitterService object to TweetMode.Extended.

So this is weird, I've not seen this before. This is a '280' character, or 'extended' tweet. For some reason, if you request this tweet without 'extended' support enabled then instead of returning the media information like it should, it removes that detail and places a Twitter wrapped link (t.co link) to the tweet itself.

If you look at the json below, which is returned when extended tweets aren't enabled, you can see that 'truncated' is true indicating the tweet is oversized, the media data is missing, and the url detail has been added.

{
    "created_at": "Sat Oct 05 20:08:53 +0000 2019",
    "id": 1180575606280462336,
    "id_str": "1180575606280462336",
    "text": "These are the perfect tasty satisfying breakfast snack packed with crunchy Cool Ranch Doritos! \ud83c\udf7d Can we make this h\u2026 https:\/\/t.co\/1JmxOAGs4C",
    "truncated": true,
    "entities": {
        "hashtags": [],
        "symbols": [],
        "user_mentions": [],
        "urls": [
            {
                "url": "https:\/\/t.co\/1JmxOAGs4C",
                "expanded_url": "https:\/\/twitter.com\/i\/web\/status\/1180575606280462336",
                "display_url": "twitter.com\/i\/web\/status\/1\u2026",
                "indices": [
                    117,
                    140
                ]
            }
        ]
    },
    "source": "\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e",
    "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": 1090471862226903040,
        "id_str": "1090471862226903040",
        "name": "PopTartADay",
        "screen_name": "PopTartADay",
        "location": "Chicago, IL",
        "description": "Follow on Instagram: @poptartaday - Parody Account. Not affiliated with the brands on my page.",
        "url": null,
        "entities": {
            "description": {
                "urls": []
            }
        },
        "protected": false,
        "followers_count": 5258,
        "friends_count": 0,
        "listed_count": 9,
        "created_at": "Wed Jan 30 04:48:46 +0000 2019",
        "favourites_count": 83,
        "utc_offset": null,
        "time_zone": null,
        "geo_enabled": true,
        "verified": false,
        "statuses_count": 343,
        "lang": null,
        "contributors_enabled": false,
        "is_translator": false,
        "is_translation_enabled": false,
        "profile_background_color": "000000",
        "profile_background_image_url": "http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png",
        "profile_background_image_url_https": "https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png",
        "profile_background_tile": false,
        "profile_image_url": "http:\/\/pbs.twimg.com\/profile_images\/1122299779965509632\/R7DMiGkr_normal.jpg",
        "profile_image_url_https": "https:\/\/pbs.twimg.com\/profile_images\/1122299779965509632\/R7DMiGkr_normal.jpg",
        "profile_banner_url": "https:\/\/pbs.twimg.com\/profile_banners\/1090471862226903040\/1552622264",
        "profile_link_color": "E81C4F",
        "profile_sidebar_border_color": "000000",
        "profile_sidebar_fill_color": "000000",
        "profile_text_color": "000000",
        "profile_use_background_image": false,
        "has_extended_profile": false,
        "default_profile": false,
        "default_profile_image": false,
        "can_media_tag": false,
        "followed_by": 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": 29,
    "favorite_count": 94,
    "favorited": false,
    "retweeted": false,
    "possibly_sensitive": false,
    "possibly_sensitive_appealable": false,
    "lang": "en"
}

However, if you enable extended tweet support by setting the TweetMode property on the TwitterService instance before requesting the tweet, like this:

            service.TweetMode = TweetMode.Extended;

Then when you request the tweet you get the full tweet object data as expected:

{
    "created_at": "Sat Oct 05 20:08:53 +0000 2019",
    "id": 1180575606280462336,
    "id_str": "1180575606280462336",
    "full_text": "These are the perfect tasty satisfying breakfast snack packed with crunchy Cool Ranch Doritos! \ud83c\udf7d Can we make this happen \ud83e\udd14 @doritos https:\/\/t.co\/N9oLX90Ex5",
    "truncated": false,
    "display_text_range": [
        0,
        131
    ],
    "entities": {
        "hashtags": [],
        "symbols": [],
        "user_mentions": [
            {
                "screen_name": "Doritos",
                "name": "Doritos",
                "id": 31143489,
                "id_str": "31143489",
                "indices": [
                    123,
                    131
                ]
            }
        ],
        "urls": [],
        "media": [
            {
                "id": 1180575577746620417,
                "id_str": "1180575577746620417",
                "indices": [
                    132,
                    155
                ],
                "media_url": "http:\/\/pbs.twimg.com\/media\/EGI_O6YWwAEZ7SG.jpg",
                "media_url_https": "https:\/\/pbs.twimg.com\/media\/EGI_O6YWwAEZ7SG.jpg",
                "url": "https:\/\/t.co\/N9oLX90Ex5",
                "display_url": "pic.twitter.com\/N9oLX90Ex5",
                "expanded_url": "https:\/\/twitter.com\/PopTartADay\/status\/1180575606280462336\/photo\/1",
                "type": "photo",
                "sizes": {
                    "thumb": {
                        "w": 150,
                        "h": 150,
                        "resize": "crop"
                    },
                    "medium": {
                        "w": 1200,
                        "h": 1200,
                        "resize": "fit"
                    },
                    "large": {
                        "w": 2000,
                        "h": 2000,
                        "resize": "fit"
                    },
                    "small": {
                        "w": 680,
                        "h": 680,
                        "resize": "fit"
                    }
                },
                "features": {
                    "all": {
                        "tags": [
                            {
                                "type": "user",
                                "user_id": "31143489",
                                "screen_name": "Doritos",
                                "name": "Doritos"
                            }
                        ]
                    },
                    "orig": {
                        "faces": [
                            {
                                "x": 1429,
                                "y": 1501,
                                "h": 93,
                                "w": 93
                            },
                            {
                                "x": 376,
                                "y": 1416,
                                "h": 156,
                                "w": 156
                            }
                        ]
                    },
                    "medium": {
                        "faces": [
                            {
                                "x": 857,
                                "y": 900,
                                "h": 55,
                                "w": 55
                            },
                            {
                                "x": 225,
                                "y": 849,
                                "h": 93,
                                "w": 93
                            }
                        ]
                    },
                    "large": {
                        "faces": [
                            {
                                "x": 1429,
                                "y": 1501,
                                "h": 93,
                                "w": 93
                            },
                            {
                                "x": 376,
                                "y": 1416,
                                "h": 156,
                                "w": 156
                            }
                        ]
                    },
                    "small": {
                        "faces": [
                            {
                                "x": 485,
                                "y": 510,
                                "h": 31,
                                "w": 31
                            },
                            {
                                "x": 127,
                                "y": 481,
                                "h": 53,
                                "w": 53
                            }
                        ]
                    }
                }
            }
        ]
    },
    "extended_entities": {
        "media": [
            {
                "id": 1180575577746620417,
                "id_str": "1180575577746620417",
                "indices": [
                    132,
                    155
                ],
                "media_url": "http:\/\/pbs.twimg.com\/media\/EGI_O6YWwAEZ7SG.jpg",
                "media_url_https": "https:\/\/pbs.twimg.com\/media\/EGI_O6YWwAEZ7SG.jpg",
                "url": "https:\/\/t.co\/N9oLX90Ex5",
                "display_url": "pic.twitter.com\/N9oLX90Ex5",
                "expanded_url": "https:\/\/twitter.com\/PopTartADay\/status\/1180575606280462336\/photo\/1",
                "type": "photo",
                "sizes": {
                    "thumb": {
                        "w": 150,
                        "h": 150,
                        "resize": "crop"
                    },
                    "medium": {
                        "w": 1200,
                        "h": 1200,
                        "resize": "fit"
                    },
                    "large": {
                        "w": 2000,
                        "h": 2000,
                        "resize": "fit"
                    },
                    "small": {
                        "w": 680,
                        "h": 680,
                        "resize": "fit"
                    }
                },
                "features": {
                    "all": {
                        "tags": [
                            {
                                "type": "user",
                                "user_id": "31143489",
                                "screen_name": "Doritos",
                                "name": "Doritos"
                            }
                        ]
                    },
                    "orig": {
                        "faces": [
                            {
                                "x": 1429,
                                "y": 1501,
                                "h": 93,
                                "w": 93
                            },
                            {
                                "x": 376,
                                "y": 1416,
                                "h": 156,
                                "w": 156
                            }
                        ]
                    },
                    "medium": {
                        "faces": [
                            {
                                "x": 857,
                                "y": 900,
                                "h": 55,
                                "w": 55
                            },
                            {
                                "x": 225,
                                "y": 849,
                                "h": 93,
                                "w": 93
                            }
                        ]
                    },
                    "large": {
                        "faces": [
                            {
                                "x": 1429,
                                "y": 1501,
                                "h": 93,
                                "w": 93
                            },
                            {
                                "x": 376,
                                "y": 1416,
                                "h": 156,
                                "w": 156
                            }
                        ]
                    },
                    "small": {
                        "faces": [
                            {
                                "x": 485,
                                "y": 510,
                                "h": 31,
                                "w": 31
                            },
                            {
                                "x": 127,
                                "y": 481,
                                "h": 53,
                                "w": 53
                            }
                        ]
                    }
                }
            }
        ]
    },
    "source": "\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e",
    "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": 1090471862226903040,
        "id_str": "1090471862226903040",
        "name": "PopTartADay",
        "screen_name": "PopTartADay",
        "location": "Chicago, IL",
        "description": "Follow on Instagram: @poptartaday - Parody Account. Not affiliated with the brands on my page.",
        "url": null,
        "entities": {
            "description": {
                "urls": []
            }
        },
        "protected": false,
        "followers_count": 5258,
        "friends_count": 0,
        "listed_count": 9,
        "created_at": "Wed Jan 30 04:48:46 +0000 2019",
        "favourites_count": 83,
        "utc_offset": null,
        "time_zone": null,
        "geo_enabled": true,
        "verified": false,
        "statuses_count": 343,
        "lang": null,
        "contributors_enabled": false,
        "is_translator": false,
        "is_translation_enabled": false,
        "profile_background_color": "000000",
        "profile_background_image_url": "http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png",
        "profile_background_image_url_https": "https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png",
        "profile_background_tile": false,
        "profile_image_url": "http:\/\/pbs.twimg.com\/profile_images\/1122299779965509632\/R7DMiGkr_normal.jpg",
        "profile_image_url_https": "https:\/\/pbs.twimg.com\/profile_images\/1122299779965509632\/R7DMiGkr_normal.jpg",
        "profile_banner_url": "https:\/\/pbs.twimg.com\/profile_banners\/1090471862226903040\/1552622264",
        "profile_link_color": "E81C4F",
        "profile_sidebar_border_color": "000000",
        "profile_sidebar_fill_color": "000000",
        "profile_text_color": "000000",
        "profile_use_background_image": false,
        "has_extended_profile": false,
        "default_profile": false,
        "default_profile_image": false,
        "can_media_tag": false,
        "followed_by": 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": 29,
    "favorite_count": 94,
    "favorited": false,
    "retweeted": false,
    "possibly_sensitive": false,
    "possibly_sensitive_appealable": false,
    "lang": "en"
}
Yortw commented 4 years ago

Note: after setting the tweetmode to extended, the Text property of the tweet object will be null. If you want the text you'll need to use the FullText property instead.

Yortw commented 4 years ago

Closing as no response and I assume the solution posted works (does for me).