获取图像 &来自带有 statuses/user_timeline API 的推文的外部 URL [英] Fetch Image & External URL from Tweets with statuses/user_timeline API

查看:19
本文介绍了获取图像 &来自带有 statuses/user_timeline API 的推文的外部 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望提取推文中出现的外部网址的值.加上该 URL 生成的缩略图.

I wish to extract value for External URL present in the Tweet. Plus the generated Thumbnail of that URL.

示例推文:

http://prntscr.com/ogdqey

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

来自 Twitter statuses/user_timeline API 的输出 -

Output from 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

URL entity is a blank array. If the link is not present in the Tweet's text itself, API doesn't return it in the URL entity. I've tried with and without tweet_mode=extended

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

Surprisingly, Twitter does return URL for few such Tweets. One example is below.

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.

Why the response is random? It does return URL for Bill Gates' Tweet but not for the one mentioned earlier in my question.

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

How can I have both External URL and the Thumbnail displayed by Twitter?

我的最终 API 调用 -

My final API call -

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 是 Tweet 文本的一部分,因此它也是 URL 实体对象的一部分.

The first of the two examples you provide is posted by the Twitter Ads platform, so the attached card is not part of the Tweet. There is no way to get that via the API. In the second case, the URL is part of the Tweet text, so it is also part of the URL entities object.

这篇关于获取图像 &amp;来自带有 statuses/user_timeline API 的推文的外部 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆