首页 > 解决方案 > tweet_mode=extended 是否与 Twitter statuses/user_timeline API 一起使用?

问题描述

在https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline.html没有提到 tweet_mode

我想知道我是否使用了错误的 API 才能利用 tweet_mode?

在我的应用程序中,我提供了 tweet_mode=extended 参数,但它没有任何效果。我的代码...

  // 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

标签: restapitwitter

解决方案


是的,您可以将 tweet_mode 与 statuses/user_timeline API 一起使用。不过,转推是一种特殊情况。检查 retweeted_status 对象,如https://dev.to/kehers/formatting-tweets-a-look-at-extended-tweets-retweets-and-quotes-n5j所述

简而言之,如果一条推文是转推,则必须在 $tweet->retweeted_status->full_text 访问扩展推文。因此,有必要在您的代码中检查每个推文对象是否具有 retweeted_status 属性。


推荐阅读