您有推文的 ID,在本例中为 1102112466283175936
您可以使用 Twitter API 来获取 Tweet 对象。图片信息在includes数据中。
API 查询是通过 /2/tweets/:id 端点进行的,图像 URL 的路径是 includes.media.url。例如:
$ twurl -j "/2/tweets/1102112466283175936?media.fields=url&expansions=attachments.media_keys"
{
"data": {
"attachments": {
"media_keys": [
"3_1102112450588147712"
]
},
"id": "1102112466283175936",
"text": "5000 selfies make up this iconic image of @jeremycorbyn in today's @ObserverUK, calling on him to bring courage and leadership to unite @UKLabour MPs behind a #PublicVote on #Brexit. RT to support! [shortened link]"
},
"includes": {
"media": [
{
"media_key": "3_1102112450588147712",
"type": "photo",
"url": "https://pbs.twimg.com/media/D0t9bz_XgAAl3hD.jpg"
}
]
}
}
您可以使用 Tweepy 库从 Python 访问 API。其他 API 库可用。