How to get source video URL from user tweet timeline using twitter API V2

Cinya

I am using following url for fetching users tweets.

https://api.twitter.com/2/users/{user_twitter_id}/tweets

Following are my Request parameters

query_params = {
    'max_results': max_results,
    'expansions': 'attachments.media_keys',
    'tweet.fields': 'id,created_at,text,author_id,in_reply_to_user_id,referenced_tweets,attachments,withheld,geo,entities,public_metrics,possibly_sensitive,source,lang,context_annotations,conversation_id,reply_settings',
    'media.fields': 'media_key,duration_ms,height,preview_image_url,type,url,width,public_metrics,non_public_metrics,organic_metrics,promoted_metrics,alt_text'
}

Below is the response I am getting inside "Includes" which have media list

"includes": {
    "media": [
        {
            "height": 750,
            "media_key": "3_1489397927281840131",
            "type": "photo",
            "url": "https://pbs.twimg.com/media/FKtnhhDWUAMtyBi.jpg",
            "width": 1125
        },
        {
            "height": 750,
            "media_key": "3_1489397930452783110",
            "type": "photo",
            "url": "https://pbs.twimg.com/media/FKtnhs3XEAYeMkP.jpg",
            "width": 1125
        },
        {
            "height": 750,
            "media_key": "3_1489397944214302727",
            "type": "photo",
            "url": "https://pbs.twimg.com/media/FKtnigIXMAcTO6t.jpg",
            "width": 1125
        },
        {
            "duration_ms": 242784,
            "height": 1080,
            "media_key": "13_1489018359819771906",
            "preview_image_url": "https://pbs.twimg.com/media/FKoOePDWYAA1ZZB.jpg",
            "public_metrics": {
                "view_count": 275300
            },
            "type": "video",
            "width": 1920
        },
        {
            "height": 2400,
            "media_key": "3_1488933061307809794",
            "type": "photo",
            "url": "https://pbs.twimg.com/media/FKnAuwWWQAIZZ8J.jpg",
            "width": 3000
        },
        {
            "height": 2000,
            "media_key": "3_1488640905187938304",
            "type": "photo",
            "url": "https://pbs.twimg.com/media/FKi3BB_X0AA47_h.jpg",
            "width": 3000
        },
        {
            "duration_ms": 41374,
            "height": 1080,
            "media_key": "13_1488623384250527746",
            "preview_image_url": "https://pbs.twimg.com/amplify_video_thumb/1488623384250527746/img/K2fiO7GwjmxL0H89.jpg",
            "public_metrics": {
                "view_count": 239341
            },
            "type": "video",
            "width": 1080
        },
        {
            "height": 2000,
            "media_key": "3_1488548514921603078",
            "type": "photo",
            "url": "https://pbs.twimg.com/media/FKhi_NbWYAYqP04.jpg",
            "width": 3000
        },
        {
            "height": 750,
            "media_key": "3_1488336416732028931",
            "type": "photo",
            "url": "https://pbs.twimg.com/media/FKeiFeGXIAMgHQx.jpg",
            "width": 1125
        },
        {
            "duration_ms": 53136,
            "height": 1080,
            "media_key": "13_1488316251667582978",
            "preview_image_url": "https://pbs.twimg.com/amplify_video_thumb/1488316251667582978/img/DE2q07gtwoARK76r.jpg",
            "public_metrics": {
                "view_count": 214984
            },
            "type": "video",
            "width": 1080
        },
        {
            "duration_ms": 40248,
            "height": 1080,
            "media_key": "13_1488154727544152064",
            "preview_image_url": "https://pbs.twimg.com/media/FKb85iAXoAou4ED.jpg",
            "public_metrics": {
                "view_count": 242329
            },
            "type": "video",
            "width": 1080
        },
        {
            "height": 913,
            "media_key": "3_1487927712761229314",
            "type": "photo",
            "url": "https://pbs.twimg.com/media/FKYuXxKXsAIbXd2.jpg",
            "width": 1200
        },
        {
            "duration_ms": 35785,
            "height": 1080,
            "media_key": "13_1487538546948939777",
            "preview_image_url": "https://pbs.twimg.com/amplify_video_thumb/1487538546948939777/img/qzUmEZKmD6ii_0dM.jpg",
            "public_metrics": {
                "view_count": 290603
            },
            "type": "video",
            "width": 1080
        }
    ]
}

As you can see in response inside media we have type video and media key, but no actual video url all we can see is video thumbnail. So please tell me how we can fetch video urls along with preview image url

Andy Piper

There are a couple of things to note here:

  • in Twitter API v2, at the time of writing this answer in Feb 2022, the video URL is not currently available. This is a known omission that Twitter is working on.

  • in Twitter API v1.1, you generally should be able to get the video URLs. There are two additional things to know about...

    • if the Tweet is a longer (more than 140 characters) Tweet, then you will need to add tweet_mode=extended to your API call to ensure that the whole Tweet data and extended entities are included. You can tell if you have not retrieved the whole Tweet if the truncated field value is true. This is the case in your example Tweet ID above. Using tweet_mode=extended you will see the video URLs.
    • if the Tweet is from the Ads platform, the video may be part of a Ads card format, and these are not served via the API. You can tell this by checking the source field for evidence that the Tweet was posted as an ad. The advertiser is able to mark the media as not for wider syndication / API access in that case, and the video URL is not returned in the API.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to get retrieve twitter user id from twitter handle using the twitter v2 API

how to get the full tweet of the user timeline with twitter4j?

Twitter API V2 video url

How to retrieve/find with specific text on tweet from user timeline twitter with python

How to get more than 20 results from a user timeline using processing and Twitter4j?

How to get twitter user_timeline using Mono?

How can I query keywords within a user's timeline using Twitter's API v1.1?

Get latest tweet from user_timeline with twit npm

Get a Twitter user timeline

Twitter API how to get the latest tweet | Python

How to tweet multiple images using twitter API?

How to favourite Tweet using Twitter API

How to get other user's mention timeline of twitter with twitter4j api?

How can I get a Twitter public timeline with no user authentication using Twitter4j?

How to get only Tweet (only posts) from the timeline?

Twitter API V2 create tweet with media PHP

How to get thumbnail of youtube video from url using php and API

How to print tweet from from specific profile in python using twitter api

How do i get user images on twitter using Twitter API?

Can we get previous tweet using Twitter Streaming API?

Twitter - How to embed native video from someone else's tweet into a New Tweet or a DM

Get Historical Tweet Metadata from Twitter API in Python

How can I get a bigger Twitter Video size from the API?

How to know the number of photos in a Tweet from Twitter API Java JSON

How to get user timeline using fabric?

Has a user seen a certain tweet? Twitter API

How to get an image from a tweet using tweepy

Is it possible to read tweet-text of a tweet URL without twitter API?

Twitter API Truncating Tweet by Adding URL

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive