当前位置: 首页 > 知识库问答 >
问题:

使用twitterapi从tweet获取视频

龙嘉誉
2023-03-14

我试图使用Twitter API从给定的推文导入视频。但是,当我使用statals/show终结点时,它不会像返回图像那样返回视频的任何扩展实体,而是返回一个链接到嵌入有视频播放器的视频容器的url实体,该视频容器包含一个指向视频的模糊链接。

以下是一个例子:

我正试图在https://twitter.com/NHL/status/633987786018717696

使用推特应用编程接口的状态/showendpoint和推特id,我得到这样的响应:

{
  "created_at": "Wed Aug 19 13:04:01 +0000 2015",
  "id": 633987786018717700,
  "id_str": "633987786018717696",
  "text": "The offseason has us missing all of our fans, even the wacky ones... especially the wacky ones. #IsItOctoberYet?\nhttps://t.co/v4UGDQpa61",
  "source": "<a href="http://twitter.com" rel="nofollow">Twitter Web Client</a>",
  "truncated": false,
  "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": 50004938,
    "id_str": "50004938",
    "name": "NHL",
    "screen_name": "NHL",
    "location": "30 cities across U.S. & Canada",
    "description": "The official source of everything you need and want to know from the National Hockey League. Read before tweeting us: http://t.co/JlyVXSpqMn",
    "url": "http://t.co/VI8RlwuVr9",
    "entities":  {
      "url":  {
        "urls":  [
           {
            "url": "http://t.co/VI8RlwuVr9",
            "expanded_url": "http://www.NHL.com",
            "display_url": "NHL.com",
            "indices":  [
              0,
              22
            ]
          }
        ]
      },
      "description":  {
        "urls":  [
           {
            "url": "http://t.co/JlyVXSpqMn",
            "expanded_url": "http://nhl.com/socialmediapolicy",
            "display_url": "nhl.com/socialmediapol…",
            "indices":  [
              118,
              140
            ]
          }
        ]
      }
    },
    "protected": false,
    "followers_count": 4130811,
    "friends_count": 2646,
    "listed_count": 18479,
    "created_at": "Tue Jun 23 15:24:18 +0000 2009",
    "favourites_count": 909,
    "utc_offset": -14400,
    "time_zone": "Eastern Time (US & Canada)",
    "geo_enabled": true,
    "verified": true,
    "statuses_count": 87436,
    "lang": "en",
    "contributors_enabled": false,
    "is_translator": false,
    "is_translation_enabled": true,
    "profile_background_color": "000000",
    "profile_background_image_url": "http://pbs.twimg.com/profile_background_images/378800000139631457/fd-xWa9G.jpeg",
    "profile_background_image_url_https": "https://pbs.twimg.com/profile_background_images/378800000139631457/fd-xWa9G.jpeg",
    "profile_background_tile": false,
    "profile_image_url": "http://pbs.twimg.com/profile_images/534776558238437376/yxrm83O7_normal.jpeg",
    "profile_image_url_https": "https://pbs.twimg.com/profile_images/534776558238437376/yxrm83O7_normal.jpeg",
    "profile_banner_url": "https://pbs.twimg.com/profile_banners/50004938/1435502670",
    "profile_link_color": "040CDE",
    "profile_sidebar_border_color": "FFFFFF",
    "profile_sidebar_fill_color": "2E2E2E",
    "profile_text_color": "0F5A80",
    "profile_use_background_image": true,
    "has_extended_profile": false,
    "default_profile": false,
    "default_profile_image": false,
    "following": true,
    "follow_request_sent": false,
    "notifications": false
  },
  "geo": null,
  "coordinates": null,
  "place": null,
  "contributors": null,
  "is_quote_status": false,
  "retweet_count": 865,
  "favorite_count": 1342,
  "entities":  {
    "hashtags":  [
       {
        "text": "IsItOctoberYet",
        "indices":  [
          96,
          111
        ]
      }
    ],
    "symbols":  [],
    "user_mentions":  [],
    "urls":  [
       {
        "url": "https://t.co/v4UGDQpa61",
        "expanded_url": "https://amp.twimg.com/v/2a0210d1-4d39-4665-a749-ea34f8efef08",
        "display_url": "amp.twimg.com/v/2a0210d1-4d3…",
        "indices":  [
          113,
          136
        ]
      }
    ]
  },
      "favorited": false,
      "retweeted": false,
      "possibly_sensitive": false,
      "possibly_sensitive_appealable": false,
      "lang": "en"
    }

遵循URL后,视频标签的来源为https://amp.twimg.com/amplify-web-player/prod/source.html?vmap_url=https://amp.twimg.com/prod/multibr_v_1/vmap/2015/08/20/13/609fc2af-1d06-4894-80be-1c231f97557a/a69baa90-58de-4d1d-b2dc-2c3ef1ab9b35.vmap

如果他们没有提供external_entity,我如何从推文中提取此视频文件?


共有3个答案

澹台玉石
2023-03-14

这里是GIF的解决方案

在Twitter API V2中,当前无法获取GIF和视频URL。我知道这太傻了。但一种解决方法是获取内容的预览图像并手动构建媒体URL。

假设我们想通过V2 API获取以下推文的GIF URL:https://twitter.com/FloodSocial/status/870042717589340160

当我们获取带有以下URL的tweet时https://api.twitter.com/2/tweets/870042717589340160?tweet.fields=attachments,作者id,创建位置,实体,id,文本

因此,这里我们可以从URL中提取DBMDLy_U0AAqUWP部分,并在应该的位置手动构建真正的GIF URLhttps://video.twimg.com/tweet_video/DBMDLy_U0AAqUWP.mp4

好了。只需要编写提取器函数。

丌官运诚
2023-03-14

使用status/showendpoint时,添加此选项tweet\u mode:“extended”以获取extended\u entities对象。响应中的此路径将具有视频URL:扩展实体。媒体[0]。视频信息。变体示例:

[
  {
    content_type: 'application/x-mpegURL',
    url: 'https://video.twimg.com/ext_tw_video/1358226.........'
  },
  {
    bitrate: 832000,
    content_type: 'video/mp4',
    url: 'https://video.twimg.com/ext_tw_video/1358226.........'
  },
  {
    bitrate: 256000,
    content_type: 'video/mp4',
    url: 'https://video.twimg.com/ext_tw_video/1358226.........'
  }
]
孔茂
2023-03-14

Twitter API现已更改,视频存储在extended_entities对象中。根据比特率,可能有多个源。这是如何检索具有最高比特率的一个:

js prettyprint-override">var bitrate = 0;
var hq_video_url;
for (var j=0; j<tweet.extended_entities.media[0].video_info.variants.length; j++) {
    if (tweet.extended_entities.media[0].video_info.variants[j].bitrate) {
        if (tweet.extended_entities.media[0].video_info.variants[j].bitrate > bitrate) {
            bitrate = tweet.extended_entities.media[0].video_info.variants[j].bitrate;
            hq_video_url = tweet.extended_entities.media[0].video_info.variants[j].url;
        }
    }
}
 类似资料:
  • 我知道您可以通过创建这样的url,使用Twitter API获取推特的特定url 然而,是否有可能获得推特的图像?我可以得到媒体图片,但这些只是人们在推特上发布的图片。我想知道是否有可能获得tweet本身的图像。

  • 当使用Tweepy收集视频推文时,通常返回的状态对象有一个属性,其中包含媒体信息,如指向mp4文件的直接链接。 但是,似乎Amplify视频(amp.twimg.com)的状态缺少此属性,因此我在收集媒体URL时遇到问题。如果您使用浏览器(例如 http://amp.twimg.com/v/50bac95c-1508-40c6-a0fc-c1b26a53a3b8)导航,他们有一个指向视频的链接,这

  • 问题内容: 我想使用Java从YouTube网址获取v = id YouTube网址格式示例: &a=GxdCwVVULXctT2lYDEPllDR0LRTutYfW ](http://www.youtube.com/watch?v=u8nQa1cJyX8&a=GxdCwVVULXctT2lYDEPllDR0LRTutYfW) //www.youtube.com/watch?v=u8nQa1cJy

  • 我们有一个网站,显示我们的YouTube视频频道和我们频道中最喜欢的视频等。我们使用YouTube数据API v2.0来获取数据。 例如: https://gdata.youtube.com/feeds/api/users/“ 用户标识 ”/播放列表?v=2 但现在这些链接返回“NetworkError: 410 Gone”。我们检查了新的YouTube Javascript API,但我们不知道

  • FFMpeg的工作速度要快得多,但仍然相当慢。 所以,我的问题是,如果有一个lib,我可以在其中执行类似以下伪代码的操作: 快速扫描视频,不看帧内的任何东西,只看标题,以找到帧的类型,并继续下一帧。 我发现如果我直接指定帧,我不会得到真正的速度差异。 除了通过API之外,FFMPEG还有什么更快的吗?

  • 我如何从youtube频道获取持续时间和浏览量都很重要的视频? 我试过这个请求: https://www.googleapis.com/youtube/v3/search?part=snippet, id 但响应不包含持续时间/视图计数。有什么想法吗?谢谢。