Search code examples
restapitwitter

Does tweet_mode=extended work with the Twitter statuses/user_timeline API?


There is no mention of tweet_mode at https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline.html

I am wondering if perhaps I am using the wrong API to be able to take advantage of tweet_mode?

In my application, I supplied the tweet_mode=extended argument and it had no effect. My code...

  // Load the Tweets.
  $args = array(
    'screen_name' => $username,
    'exclude_replies' => 'true',
    'include_rts' => 'true',
    'tweet_mode' => 'extended',
    'count' => $numitems,
  );

  $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);

  $tweets = $connection->get('statuses/user_timeline', $args);

  if (!empty($tweets)) {
    foreach ($tweets as $tweet) {
        $text = $tweet->full_text;
        // etcetera

Solution

  • Yes, you can use tweet_mode with the statuses/user_timeline API. Retweets are a special case, though. Check the retweeted_status object, as described at https://dev.to/kehers/formatting-tweets-a-look-at-extended-tweets-retweets-and-quotes-n5j

    In short, if a tweet is a retweet, the extended tweet must be accessed at $tweet->retweeted_status->full_text. Thus, it's necessary in your code to check if each tweet object has a retweeted_status property.