Python 使用 python 下载 twitter 视频(不使用 twitter api) [英] Python Downloading twitter video using python (without using twitter api)
问题描述
我想在不使用推特官方 API 的情况下下载推特视频.因此,当我在 chrome 中打开 icognito 和 chrome 开发工具并请求任何视频时,例如https://twitter.com/KTHopkins/status/1248140219490209792"我看到 twitter 请求两个重要的标题来为视频提供服务1.‘授权’2. ‘x-guest-token’
I want to download twitter video without using twitter’s official API . So when i open an icognito and chrome dev tool in chrome and request any video like "https://twitter.com/KTHopkins/status/1248140219490209792" i see twitter requests two important headers to server the video 1.‘authorization’ 2. ‘x-guest-token’
我似乎无法获得这些令牌是从哪里生成的?下面是我发送的 python 请求.
which i seem to cannot get where these tokens are generated from ? Belown is my python request which i am sending .
import requests
headers = {
'authority': 'api.twitter.com',
'dnt': '1',
'x-twitter-client-language': 'en',
# 'x-csrf-token': '6089ceeab3324243e7b952679b2b7851',
'authorization': 'Bearer AAAAAAAAAAAAAAAAAAAAANk3DgEAAAAAB0pZx4xjgXBOoalj%2FRbagurxD2M%3DG8634UVlBud8LrLG4nGo7FpN2RCO2xul5BuPKHuejUAV14O0KG',
'user-agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36',
'sec-fetch-dest': 'empty',
'x-guest-token': '1248286947669237760',
'x-twitter-active-user': 'yes',
'accept': '*/*',
'origin': 'https://twitter.com',
'sec-fetch-site': 'same-site',
'sec-fetch-mode': 'cors',
'accept-language': 'en-US,en;q=0.9,hi;q=0.8',
# 'cookie': 'personalization_id="v1_tWyK8Fn5ofSPjSAEKsnyrw=="; guest_id=v1%3A158644503604220835; ct0=6089ceeab3324243e7b952679b2b7851; _twitter_sess=BAh7CSIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7ADoPY3JlYXRlZF9hdGwrCDI2fl9xAToMY3NyZl9p%250AZCIlNmM2YjZiYTU4MzdhY2FkNDQwZjcwMGU1NDliNzEzN2Y6B2lkIiViOWUx%250AYzM5MDk3ZTQ0YzMyZDRkMGU3YTdkM2FlMGY2YQ%253D%253D--223c07ac4708a9bec30dec1e0e9c3d52544b310c; _ga=GA1.2.162154316.1586445033; _gid=GA1.2.1445748635.1586445033; gt=1248286947669237760',
}
response = requests.get('https://api.twitter.com/2/timeline/conversation/1248293309950255107.json')
print(response.text)
请帮助我获得这两个令牌.
so help me in geeting those two tokens .
推荐答案
您可以通过
curl -skL https://twitter.com/ -H 'User-Agent: Firefox' --compressed | grep -o 'gt=[0-9]*' | sed s.gt=..
我.例如,通过下载网站的内容并解析其 JavaScript.注意:User-Agent
需要设置为 Twitter 认为可以理解 JavaScript 的内容.否则,他们会发送不包含令牌的旧版网站.
i. e., by download the website's content and parse its JavaScript. Note: The User-Agent
needs to be set to something that Twitter believes to understand JavaScript. Otherwise, they send a legacy version of the website which doesn't contain the token.
这篇关于Python 使用 python 下载 twitter 视频(不使用 twitter api)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!