Use tweepy to get Twitter videos from user timeline - python

When using tweepy to collect video tweets, generally the Status object returned has an extended_entities attribute that contains media information like the direct link to the mp4 file.
It appears however that statuses with Amplify videos (amp.twimg.com) are missing this extended_entities attribute and so I am having trouble collecting the media url. They have a link to the video that is fine if you are navigating with a browser (http://amp.twimg.com/v/50bac95c-1508-40c6-a0fc-c1b26a53a3b8 for example) but this is not very useful if I just want the mp4 file.
Is there a way to collect the mp4 file from Amplify videos using tweepy? Why do these videos not have the same media information as other twitter videos?

As you can see in the official documentation, you have to opt into the extended mode via a request parameter:
"Any endpoints that return Tweets will accept a new tweet_mode request parameter. Valid request values are compat and extended, which give compatibility mode and extended mode, respectively."
So maybe you'll have better results if you explicitly pass tweet_mode='extended'. Not sure if this has been implemented in Tweepy yet. Just check the sourcecode.

Related

Can I tweet mp4 files with tweepy?

I was just wondering if it was possible to tweet an mp4 file with tweepy (maybe using api.update_with_media). I've seen a post from a few years ago saying that it's not possible with the official tweepy, but I find it really hard to believe that there's no way to do it with the official tweepy. Can anyone please help?
update_with_media was deprecated as a Twitter API method about 5 years ago. This pre-dated the ability to upload GIFs and video MP4s. If you want to post media on Twitter via the API, you must find a library that supports the media upload endpoints (and chunked uploads). The process is
upload the media file (chunked if necessary depending on size and format)
retrieve a media ID string
post a Tweet, and add the media ID to the Tweet.
Note that you can only post multiple images on a single Tweet; you can only post a single GIF or video file on a single Tweet, not multiple.
I do not believe the default Tweepy release supports this but I could be wrong, you’ll need to check the Tweepy documentation.
Do NOT use update_with_media - it’s very old and unsupported as an API path.
Also worth being aware that tweepy itself is a third party library - that we at Twitter LOVE - but this is not officially supported.

Retrieving Facebook Page comments with python script

I am building a python script that is trying to stream a screen capture to my Facebook Page and to be able to retrieve all the comments from the Facebook Live stream real time so that I can do some processing in the middle of the stream.
The Facebook App was set up (in development mode) but when I tried to retrieve the comments from my live stream, I am only able to retrieve comments with their name and id ("from") that are made as the Facebook Page Admin, not comments that are made by other users. I need the user's id, user's name and their comments.
I understand that I need to get Facebook App to be live mode in order to retrieve all the comments with their details tagged to it. When I tried to get it, it tells me that I need to get the permission approved. I tried to fill in most of the stuff and try to get the two permission (manage_page for the comments and live video API for the streaming) but I was unable to because I left the platform empty.
Below is the message I got:
You do not have any platforms eligible for review. Please configure a platform on your Settings page.
The problem is when I tried to choose a platform that was shown in the list, python script does not fall in the list of platform.
Does anyone know of a solution or a different way to achieve what I need to retrieve?
Have you tried using PyLivestream?
It can be used to stream to Facebook Live using FFmpeg (to multiple services simultaneously actually, like Periscope, YouTube etc).
It adheres to the RTMPS requirement and should be an option for you if I interpret your needs correctly.
python -m pip install PyLivestream
Facebook Live
Facebook Live requires FFmpeg >= 4.2 due to mandatory RTMPS
configure your Facebook Live stream
Put stream ID from https://www.facebook.com/live/create into the file facebook.key
Run Python script for Facebook with chosen input
Check out the PyPi PyLivestream page for details.
To be able to retrieve all the comments from the Facebook Live stream
I'm not sure if this is possible using PyLivestream alone, but the Polls API can be used to represent VideoPoll objects in the Graph API, to create polls on live video broadcasts and get real-time responses from your viewers and can be created with the
POST /{live-video-id}/polls
endpoint on a LiveVideo object.
Upon creation, the API will return a VideoPoll object ID, which you can use to manipulate the poll and query for viewer interactions.
Guess you'll have to do a bit of digging to figure out the details,
but I believe this would be the right way to approach this task.
In order to get the "from" field when retrieving the comments, you need to have manage_pages permission from your Facebook App that is linked to your Facebook Page. You will need to submit an App review for your Facebook App that usually takes 1-3 days to process. If you are lucky, it will probably take about 6-8 hours.
Once it is approved, you can request the permission and get your application to go live.
Also use the Page Access token in your "access_token" field when invoking the API so that it will allow you to pull the "from" field, which contains the id and name of the user.

Tweet mp4 files with tweepy

Hey I'd like to tweet a mp4 file generated using ffmpeg to twitter.
However it seems that there's no real native way to do this with the official tweepy.
When tried with the api.update_with_media(filename, message) method, you'll get an error, unsupported file 'video/mp4'
So first I saw a discussion where this github project was linked: Github link
But after testing out the code, the app crashs after the first INIT phase.
So next I saw this: Github pull request thread
And on that thread it was announced that there is a code to tweet video but it hasn't officialy been merged yet, and braian87b made a fork of tweepy with the code to upload videos.
However I have no idea how to install and use a fork of tweepy and how to actually use the code to tweet a video. Braian87b used this as an example code:
upload_result = api.media_upload('/home/user/video.mp4')
api.update_status(status="test tweet", media_ids=[upload_result.media_id_string])
Any help would be apreciated! :)
In the end I managed to understand it. Making a fork of my own (as the one braian87b provided was incompatible with the latest version of pip, which is what I used to install it), I was able to install the forked tweepy by using pip
pip install git+https://github.com/Spyder-exe/tweepy.git
and then the code that braian87b provided was in the end perectly good!
So using this code
upload_result = api.media_upload('/home/user/video.mp4')
api.update_status(status="test tweet", media_ids=[upload_result.media_id_string])
And making sure to put the reply_to_status_id tag before the media_ids tag, I was able to upload videos to twitter with only minor annoyances.
I know this is late, but if you want to keep using the official tweepy, you can use the imgur API to upload your media, and then tweet the link (this is what I ended up doing)
update_with_media has been deprecated for a long time and once you set up the authentication with the imgur API it's really easy.
we are sending MP4 with less duration but getting media processing status is failed. so what is the format?
ANS
Twitter currently supports the following video formats: MOV and MP4 formats for mobile apps. The minimum Twitter video length is 0.5 second and the maximum Twitter video length is 2 minutes 20 seconds (140 seconds) Twitter supports the following web video formats: MP4 video uploads with H264 format and AAC audio
Use mobile record video you will get your answer

How to get video id of the successfully uploaded youtube video?

I am uploading video to youtube by using their API. After the successful upload, i want to get the video id which i am unable to find. I have found this in the video_entry object as id.
<ns0:id xmlns:ns0="http://www.w3.org/2005/Atom">http://gdata.youtube.com/feeds/api/videos/nK1Ax6320T8</ns0:id>
Here, nK1Ax6320T8 is the video id. How can i parse it in python. Kindly help.
You'll need to parse that url parameters, Python provides a good library to do that.
There's good sample code from the YouTube data API docs that does exactly what you're asking about. Checkout line 76.

tweepy/twitter get all tweets from a location:

I have the following questions about tweepy python module
1.I am trying to retrieve all tweets for a specific location. I am able to do this by using tweepy python module (streaming API), but I get only those tweets whose geo locations are enabled, which means I would loose rest of the tweeter’s tweet who have not enabled their geo location. Is there a better way to retrieve all the tweets, given a location?
2.I use Stream.Sample method to retrieve all the tweets, Can someone tell me about the parameters used in sample method? I see count, and async as parameters. Now what should we specify here?
3.What does firehose method in tweepy.Stream do?
Any help is much appreciated
If tweepy doesn't have a feature you need, you can always access Twitter directly with an HTTP request. The full Twitter REST API is described here: https://dev.twitter.com/docs/api
The ones that seem relevant to your interest are:
GET trends/:woeid which looks up tweets by woeid, a Yahoo Identifier for collecting information about a given place/landmark/etc.
GET geo/id/:place_id which only mines geotagged tweets.
There is documentation of all the information available for a GET request but the IP address is not among the available fields: https://dev.twitter.com/docs/api/1/get/search .
Lastly, Twitter has a location search FAQ that may be of interest.

Categories