【问题标题】:How to get the URL of an Instagram post from the media_share_url?如何从 media_share_url 获取 Instagram 帖子的 URL?
【发布时间】:2021-03-21 18:45:58
【问题描述】:

当请求下载您的 Instagram 个人资料数据时,您会在 JSON 文件中获取对话。对话中的共享帖子在 JSON 文件中转换为以下内容:

{
  "sender": "username",
  "created_at": "2021-02-29T05:34:34.866155+00:00",
  "media_owner": "bloombergbusiness",
  "media_share_caption": "The world is finally losing its taste for meat. Last year was only the second since 1961 in which meat production fell and it’s headed for another decline this year.\n\nBeef is clearly declining as a percentage of total meat production—that’s huge for the climate. Emissions from its production are about 10 times higher than from either pork or chicken. \n\nNow investors are betting more than $1 billion on alternative proteins this year. Click the link in our bio to read more.",
  "media_share_url": "https://scontent-atl3-1.cdninstagram.com/v/t51.2885-15/fr/e15/s1080x1080/116427336_158250425871714_8283380464202749985_n.jpg?_nc_ht=scontent-atl3-1.cdninstagram.com&_nc_cat=106&_nc_ohc=InoAagAFZN4AX_f89en&oh=4337b2808755d718c329088688ba9fcd&oe=5F5AF234&ig_cache_key=MjM2NTE4MTQ2Mzk1OTE2MDM1MQ%3D%3D.2"
}

URLìn media_share_url 是短暂的,所以一段时间后它会过期,只需返回“URL 签名过期”。

我的问题是:

有没有办法从media_share_url 获取原始 URL?在上面的例子中是https://www.instagram.com/p/CDS0AKcn8Yf。或者,获取thumbnail url 也可以。

这可能吗?

【问题讨论】:

    标签: json url instagram


    【解决方案1】:

    如果你有这个信息,你可以使用它。

    1. 媒体 ID
    2. 帖子 ID

    您可以尝试使用它们..

    Java 代码:

       public static String getInstagramPostId(String mediaId) {
        String postId = "";
        try {
            long id = Long.parseLong(mediaId.substring(0, mediaId.indexOf('_')));
            String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
    
            while (id > 0) {
                long remainder = (id % 64);
                id = (id - remainder) / 64;
                postId = alphabet.charAt((int)remainder) + postId;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    
        return postId;
     }
    

    你可以检查这个链接的javascript

    (https://www.npmjs.com/package/big-integer)

    【讨论】:

    • 感谢您的回复。您能否提供一个带有问题中的media_share_url 的工作示例?另外,为了澄清,如问题中所述,我没有媒体 ID,但 media_share_url,它们是不同的。
    猜你喜欢
    • 1970-01-01
    • 2020-02-07
    • 1970-01-01
    • 1970-01-01
    • 2019-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多