有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java无法获取instagram个人资料图片的完整大小

几天前,我能够在我的安卓应用程序中获取inta配置文件pic,方法是从pic URL中删除vp/并将exp的分辨率从s150x150更改为s720x720,效果很好,但现在我仍然得到“无效URL签名”,因此我认为instagram已经在他们的URL中添加了签名,我通常在picurl中从vp/to/t51中删除parte。。。像这样

https://scontent-mxp1-1.cdninstagram.com/vp/xxxxxxxx/t51。。。。jpg
但是它不起作用

我不知道instagram发生了什么,有人能帮我找到解决这个问题的方法吗?或者另一种方法。谢谢


共 (1) 个答案

  1. # 1 楼答案

    以下是如何在2020年5月没有像https://www.instadp.com/这样的外部网站的情况下完成这项工作。程序也可以使用此API方法

    • 首先,确保您已登录到要执行此操作的浏览器上的Instagram帐户

    • 在此URL中输入用户名以代替“usernamehere”:

    https://www.instagram.com/usernamehere/?__a=1

    • 访问URL

    • 复制开始处“profilePage_u2;”后面的数字。这是用户ID。(它也位于JSONgraphql.user.id下。)

    • 将此URL中的数字粘贴到“numberher”的位置

    https://i.instagram.com/api/v1/users/numberhere/info/

    • 访问URL。您很可能会看到{"message": "useragent mismatch", "status": "fail"}。如果是,请执行以下步骤:

    • 如果您使用的是Chrome,请按F12或Ctrl+Shift+I或Ctrl+Shift+J打开DevTools

    • 在底部的绘图中(您会看到“控制台”、“新功能”、网络条件),单击“网络条件”

    • 在“用户代理”下,取消选中“自动选择”

    • 选择“自定义…”,然后将Instagram移动用户代理粘贴到该框中,如下所示:

    Mozilla/5.0 (Linux; Android 9; GM1903 Build/PKQ1.190110.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/75.0.3770.143 Mobile Safari/537.36 Instagram 103.1.0.15.119 Android (28/9; 420dpi; 1080x2260; OnePlus; GM1903; OnePlus7; qcom; sv_SE; 164094539)

    你可以找到更多的here

    • 不要关闭DevTools。刷新页面

      注意:有browser extensions可以做到这一点

      查看this tutorial了解如何在其他浏览器上执行此操作

    • 按Ctrl+F,然后搜索“hd\U配置文件\U图片\U url\U信息”

    • 在“URL”和“宽度”之间复制URL。它很长,所以仔细看。(它位于JSON中的user.hd_profile_pic_url_info.url下。)

    注意:像this one这样的扩展将使这部分变得更加容易

    • 将URL粘贴到地址栏中,但不要按Enter键

    • 在URL中查找“\u0026”的所有实例。在URL的后半部分应该有大约3个。这些是“&;”的JavaScript代码,但它们在地址栏URL中不起作用(如果按Enter键,您将看到Bad URL timestamp)。将它们全部替换为“&;”

    • 访问URL

    现在您有了完整的分辨率配置文件图片。:)

    更新:终于有时间写一个函数来获取这个URL。您可以在浏览器中使用它,而不必经历所有这些步骤

    async function fetchIGProfilePic(input) {
        if (!/^https?:\/\/i.instagram.com\//.test(window.location.href)) {
            if (window.confirm('fetchIGProfilePic:\n\nWe need to navigate to i.instagram.com for the request to work. (We need to make the request from the same domain as the profile pic API; CORS policy.) Please run the script after doing this.\n\nNavigate to i.instagram.com? (Ignore the 404 error.)')) {
                window.location.href = 'https://i.instagram.com/api/v1/';
                return;
            } else {
                return 'fetchIGProfilePic: Cancelled.';
            }
        }
        let response;
        let output;
        try {
            response = await fetch('https://www.instagram.com/' + input + '/?__a=1');
            if (!response.ok) {
                console.log('Failed 1st step, to fetch userID, with bad response status:' + response.status);
                return;
            }
        } catch(error) {
            console.log('Failed 1st step, to fetch userID, with ok response status: ' + error);
            return;
        }
        let userData = await response.json();
        try {
            response = await fetch('https://i.instagram.com/api/v1/users/' + userData.graphql.user.id + '/info/', {
                // The following doesn't seem to be necessary in a console request, but I kept it in in case you have issues at this stage.
                headers: {'user-agent': 'Mozilla/5.0 (Linux; Android 9; GM1903 Build/PKQ1.190110.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/75.0.3770.143 Mobile Safari/537.36 Instagram 103.1.0.15.119 Android (28/9; 420dpi; 1080x2260; OnePlus; GM1903; OnePlus7; qcom; sv_SE; 164094539)'
                }
            });
            if (!response.ok) {
                console.log('Failed 2nd step, to fetch profile pic URL, with bad response status: ' + response.status);
                window.alert('fetchIGProfilePic:\n\nYou might not be logged in, which is necesary for the request to work. Please log into an Instagram account, then run this script again.');
                return;
            }
        } catch(error) {
            console.log('Failed 2nd step, to fetch profile pic URL, with ok response status: ' + error);
            return;
        }
        let profileData = await response.json();
        console.log('Full-size profile pic URL of ' + input + ':\n' + profileData.user.hd_profile_pic_url_info.url);
    }
    
    fetchIGProfilePic('instagram'); // Enter the username here.
    

    在浏览器中,按F12打开控制台,然后粘贴脚本。您将用户名放在下括号中,然后按Enter键,它将在控制台中检索URL。运行脚本时,请确保您在https://i.instagram.com/api/v1/上并登录到Instagram帐户