Search code examples
twittertwitter-rest-api

Why is this quoted tweet pointing to itself?


I am retrieving tweets with the Twitter API and I do this: I check that they have a quoted_status, then I replace the URL in url_info->url that has the tweet_data->quoted_status->id_str within the url_info->expanded_url. This way, I know the URL is the one of the quoted tweet, and I can recover the data and display it below.

And this usually works, but not with this tweet:

stdClass Object
(
[created_at] => Wed Dec 14 08:30:32 +0000 2016
[id] => 8.0895229853789E+17
[id_str] => 808952298537885696
[text] => Volem felicitar al Centre d'Estudis Montseny, guanyadors d'aquest concurs, i a @stlisieux, que han estat finalistes… 'shortened_url'/CGqkTNPPB1
[truncated] => 1
[entities] => stdClass Object
    (
        [hashtags] => Array
            (
            )

        [symbols] => Array
            (
            )

        [user_mentions] => Array
            (
                [0] => stdClass Object
                    (
                        [screen_name] => stlisieux
                        [name] => Col·legi ST Lisieux
                        [id] => 3064329677
                        [id_str] => 3064329677
                        [indices] => Array
                            (
                                [0] => 79
                                [1] => 89
                            )

                    )

            )

        [urls] => Array
            (
                [0] => stdClass Object
                    (
                        [url] => 'shortened_url'CGqkTNPPB1
                        [expanded_url] => https://twitter.com/i/web/status/808952298537885696
                        [display_url] => twitter.com/i/web/status/8…
                        [indices] => Array
                            (
                                [0] => 117
                                [1] => 140
                            )

                    )

            )

    )

[source] => Twitter Web Client
[in_reply_to_status_id] => 
[in_reply_to_status_id_str] => 
[in_reply_to_user_id] => 
[in_reply_to_user_id_str] => 
[in_reply_to_screen_name] => 
[user] => stdClass Object
    (
        [id] => 493037120
        [id_str] => 493037120
        [name] => Clickedu
        [screen_name] => Clickedu
        [location] => España
        [description] => La plataforma para colegios e institutos. | La plataforma per a escoles i instituts. 'shortened_url'/NBZbqw7Qpn
        [url] => 'shortened_url'/00a8v8WUv5
        [entities] => stdClass Object
            (
                [url] => stdClass Object
                    (
                        [urls] => Array
                            (
                                [0] => stdClass Object
                                    (
                                        [url] => 'shortened_url'/00a8v8WUv5
                                        [expanded_url] => http://www.clickartedu.com/
                                        [display_url] => clickartedu.com
                                        [indices] => Array
                                            (
                                                [0] => 0
                                                [1] => 22
                                            )

                                    )

                            )

                    )

                [description] => stdClass Object
                    (
                        [urls] => Array
                            (
                                [0] => stdClass Object
                                    (
                                        [url] => 'shortened_url'/NBZbqw7Qpn
                                        [expanded_url] => http://www.clickedu.eu
                                        [display_url] => clickedu.eu
                                        [indices] => Array
                                            (
                                                [0] => 85
                                                [1] => 107
                                            )

                                    )

                            )

                    )

            )

        [protected] => 
        [followers_count] => 2960
        [friends_count] => 1998
        [listed_count] => 79
        [created_at] => Wed Feb 15 11:29:55 +0000 2012
        [favourites_count] => 8529
        [utc_offset] => 3600
        [time_zone] => Madrid
        [geo_enabled] => 1
        [verified] => 
        [statuses_count] => 3840
        [lang] => ca
        [contributors_enabled] => 
        [is_translator] => 
        [is_translation_enabled] => 
        [profile_background_color] => AD0C40
        [profile_background_image_url] => http://pbs.twimg.com/profile_background_images/444501732022697984/vMM1qgYt.jpeg
        [profile_background_image_url_https] => https://pbs.twimg.com/profile_background_images/444501732022697984/vMM1qgYt.jpeg
        [profile_background_tile] => 
        [profile_image_url] => http://pbs.twimg.com/profile_images/567973366670172160/1opAPyhE_normal.jpeg
        [profile_image_url_https] => https://pbs.twimg.com/profile_images/567973366670172160/1opAPyhE_normal.jpeg
        [profile_banner_url] => https://pbs.twimg.com/profile_banners/493037120/1477042035
        [profile_link_color] => AD0C40
        [profile_sidebar_border_color] => FFFFFF
        [profile_sidebar_fill_color] => DDEEF6
        [profile_text_color] => 333333
        [profile_use_background_image] => 1
        [has_extended_profile] => 
        [default_profile] => 
        [default_profile_image] => 
        [following] => 
        [follow_request_sent] => 
        [notifications] => 
        [translator_type] => none
    )

[geo] => 
[coordinates] => 
[place] => 
[contributors] => 
[is_quote_status] => 1
[quoted_status_id] => 8.0870805032451E+17
[quoted_status_id_str] => 808708050324508672
[quoted_status] => stdClass Object
    (
        [created_at] => Tue Dec 13 16:19:58 +0000 2016
        [id] => 8.0870805032451E+17
        [id_str] => 808708050324508672
        [text] => Així és com veuen l’ictus els alumnes del Centre d’Estudis Montseny, que han guanyat el 18è concurs Pinta La Marató… 'shortened_url'/tts4uGmKWy
        [truncated] => 1
        [entities] => stdClass Object
            (
                [hashtags] => Array
                    (
                    )

                [symbols] => Array
                    (
                    )

                [user_mentions] => Array
                    (
                    )

                [urls] => Array
                    (
                        [0] => stdClass Object
                            (
                                [url] => 'shortened_url'/tts4uGmKWy
                                [expanded_url] => https://twitter.com/i/web/status/808708050324508672
                                [display_url] => twitter.com/i/web/status/8…
                                [indices] => Array
                                    (
                                        [0] => 117
                                        [1] => 140
                                    )

                            )

                    )

            )

        [source] => Twitter Web Client
        [in_reply_to_status_id] => 
        [in_reply_to_status_id_str] => 
        [in_reply_to_user_id] => 
        [in_reply_to_user_id_str] => 
        [in_reply_to_screen_name] => 
        [user] => stdClass Object
            (
                [id] => 18045654
                [id_str] => 18045654
                [name] => La Marató
                [screen_name] => la_marato
                [location] => Catalunya
                [description] => El 18 de desembre La Marató fa 25 anys amb un programa dedicat a l'ictus i les lesions medul·lars i cerebrals traumà tiques.
                [url] => 'shortened_url'/iCXlb20x3w
                [entities] => stdClass Object
                    (
                        [url] => stdClass Object
                            (
                                [urls] => Array
                                    (
                                        [0] => stdClass Object
                                            (
                                                [url] => 'shortened_url'/iCXlb20x3w
                                                [expanded_url] => http://www.tv3.cat/marato/
                                                [display_url] => tv3.cat/marato/
                                                [indices] => Array
                                                    (
                                                        [0] => 0
                                                        [1] => 22
                                                    )

                                            )

                                    )

                            )

                        [description] => stdClass Object
                            (
                                [urls] => Array
                                    (
                                    )

                            )

                    )

                [protected] => 
                [followers_count] => 46627
                [friends_count] => 352
                [listed_count] => 333
                [created_at] => Thu Dec 11 11:38:21 +0000 2008
                [favourites_count] => 1469
                [utc_offset] => 3600
                [time_zone] => Madrid
                [geo_enabled] => 
                [verified] => 
                [statuses_count] => 3160
                [lang] => ca
                [contributors_enabled] => 
                [is_translator] => 
                [is_translation_enabled] => 
                [profile_background_color] => DCE4E8
                [profile_background_image_url] => http://pbs.twimg.com/profile_background_images/378800000099697740/e6dc40b2a9233a582dc14394aed732a7.jpeg
                [profile_background_image_url_https] => https://pbs.twimg.com/profile_background_images/378800000099697740/e6dc40b2a9233a582dc14394aed732a7.jpeg
                [profile_background_tile] => 
                [profile_image_url] => http://pbs.twimg.com/profile_images/748843776345513985/WXSEA15G_normal.jpg
                [profile_image_url_https] => https://pbs.twimg.com/profile_images/748843776345513985/WXSEA15G_normal.jpg
                [profile_banner_url] => https://pbs.twimg.com/profile_banners/18045654/1481702408
                [profile_link_color] => 0084B4
                [profile_sidebar_border_color] => FFFFFF
                [profile_sidebar_fill_color] => DDEEF6
                [profile_text_color] => 333333
                [profile_use_background_image] => 1
                [has_extended_profile] => 
                [default_profile] => 
                [default_profile_image] => 
                [following] => 
                [follow_request_sent] => 
                [notifications] => 
                [translator_type] => none
            )

        [geo] => 
        [coordinates] => 
        [place] => 
        [contributors] => 
        [is_quote_status] => 
        [retweet_count] => 15
        [favorite_count] => 21
        [favorited] => 
        [retweeted] => 
        [possibly_sensitive] => 
        [lang] => und
    )

[retweet_count] => 2
[favorite_count] => 2
[favorited] => 
[retweeted] => 
[possibly_sensitive] => 
[lang] => und
)

Here, the [expanded_url] => https://twitter.com/i/web/status/808952298537885696 is pointing to the tweet itself, not to the quoted tweet as usual.

Is this common? How can I link the shortened URL in the text body with the quoted tweet? I don't see any connexion between them, so I don't know how to replace the link for the tweet content, as I don't know how to differentiate the quoted tweet URL from other URLs that may be in the tweet.


Solution

  • Since the truncated value in this Tweet is true (1), this indicates that you are looking at an extended Tweet. You can read more about the new Tweet format in the Twitter developer Upcoming Changes to Tweets documentation. If you use the tweet_mode=extended option you will be able to retrieve the full Tweet without the embedded link to the web version of the Tweet.