dtuy84033 2016-11-16 11:36
浏览 103
已采纳

Twitter API响应并不总是按预期返回实体媒体

Consider a call to retrieve a Twitter user's list of favorites using abraham/twitteroauth PHP library:

https://api.twitter.com/1.1/favorites/list.json

Given the following parameters:

$params = array(
    'screen_name' => $screenName,
    'count' => $count,
    'include_entities' => true,
);

Whereas all requested tweets actually show/embed a photo on the Twitter site, the related media fields expected to be found within the entities parent fields are not always present in the API response.

Here's a tweet whose response include the field, and another one whose response does NOT include it. You'll found respective JSON responses in this Gist: https://gist.github.com/davidloubere/8331a2b523772d99c669e1e720aa4afc

Does someone have an explanation for this?

  • 写回答

1条回答 默认 最新

  • dongqintong8972 2016-11-22 22:56
    关注

    This happens because recently Twitter announced REST API changes that introduced two Tweets types:

    • Classic Tweet - A Tweet object where the total length of the text
      content does not exceed 140 characters
    • Extended Tweet - A Tweet object which includes hidden entities (e.g. leading @mentions and trailing attachment) and where the
      text content exceeds 140 characters in length.

    They also introduced Compatibility mode which is default when you work with Twitter REST API. There is also Extended which you should set explicitly.

    Citate from the documentation at https://dev.twitter.com/overview/api/upcoming-changes-to-tweets:

    "There will be two modes for rendering Tweet JSON objects to API clients: compatibility mode and extended mode. Compatibility mode is the default mode for the public REST and Streaming APIs and Gnip products, and is designed to not break existing clients. ... The existing text field will contain a truncated version of the Tweet text, followed by an ellipsis character, a space, and a shortened self-permalink URL. ... The existing entity fields (mentions, urls, media, etc.), will only contain entities that are fully contained within the text value."

    So, the first Tweet is Classic, and the second is Extended that gets truncated when you fetch it in Compatibility mode. You can get its full version by setting tweet_mode=extended in your Twitter REST API call.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题