gpt4 book ai didi

twitter - 使用 statuses/user_timeline API 从推文中获取图像和外部 URL

转载 作者:行者123 更新时间:2023-12-02 10:08:57 25 4
gpt4 key购买 nike

我希望提取推文中存在的外部 URL 的值。加上生成的该 URL 的缩略图

示例推文:

http://prntscr.com/ogdqey

https://twitter.com/JarirBookstore/status/1151506848387870720

来自 Twitter statuses/user_timeline API 的输出 -

{
"created_at": "Wed Jul 17 15:00:01 +0000 2019",
"id": 1151506848387870720,
"id_str": "1151506848387870720",
"full_text": "عروض #صيف_هواوي على أجهزة التابلت والميت بوك المختلفة \nالعرض ساري الى 21 يوليو",
"truncated": false,
"display_text_range": [
0,
78
],
"entities": {
"hashtags": [
{
"text": "صيف_هواوي",
"indices": [
5,
15
]
}
],
"symbols": [],
"user_mentions": [],
"urls": []
},
"source": "<a href=\"https:\/\/ads-api.twitter.com\" rel=\"nofollow\">Twitter Ads Composer<\/a>",
"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": 281376243,
"id_str": "281376243"
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 0,
"favorite_count": 3,
"favorited": false,
"retweeted": false,
"lang": "ar"
},

URL 实体是一个空数组。如果推文文本本身不存在该链接,API 不会在 URL 实体中返回它。我尝试过使用和不使用 tweet_mode=extended

令人惊讶的是,Twitter 确实返回了少数此类推文的 URL。下面是一个示例。

https://twitter.com/BillGates/status/1150605518291001345

API 响应:

{
"created_at": "Mon Jul 15 03:18:27 +0000 2019",
"id": 1150605518291001345,
"id_str": "1150605518291001345",
"full_text": "I recently wrote about how people with tech skills can find fascinating problems to work on in global health and development. I was excited to come across this @techreview article about African machine learning researchers who are already doing just that. https:\/\/t.co\/3e1d2QvvH4",
"truncated": false,
"display_text_range": [
0,
279
],
"entities": {
"hashtags": [],
"symbols": [],
"user_mentions": [
{
"screen_name": "techreview",
"name": "MIT Technology Review",
"id": 15808647,
"id_str": "15808647",
"indices": [
160,
171
]
}
],
"urls": [
{
"url": "https:\/\/t.co\/3e1d2QvvH4",
"expanded_url": "https:\/\/b-gat.es\/2xMsbdh",
"display_url": "b-gat.es\/2xMsbdh",
"indices": [
256,
279
]
}
]
},
"source": "<a href=\"https:\/\/www.sprinklr.com\" rel=\"nofollow\">Sprinklr<\/a>",
"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": 50393960,
"id_str": "50393960"
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 1320,
"favorite_count": 6719,
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"lang": "en"
},

为什么响应是随机的?它确实返回比尔·盖茨推文的 URL,但不返回我问题中前面提到的推文的 URL。

如何让 Twitter 同时显示外部 URL 和缩略图?

我的最终 API 调用 -

https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=jarirbookstore&count=100&exclude_replies=true&trim_user=true&include_rts=false&tweet_mode=extended

最佳答案

您提供的两个示例中的第一个是由 Twitter 广告平台发布的,因此所附卡片不是推文的一部分。无法通过 API 获取该信息。在第二种情况下,URL 是推文文本的一部分,因此它也是 URL 实体对象的一部分。

关于twitter - 使用 statuses/user_timeline API 从推文中获取图像和外部 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57080605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com