以下是截至 2020 年 5 月在没有像 https://www.instadp.com/ 这样的外部网站的情况下的操作方法。程序也可以使用此 API 方法。
https://www.instagram.com/usernamehere/?__a=1
https://i.instagram.com/api/v1/users/numberhere/info/
-
访问网址。您很可能会看到{"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;一加;GM1903;一加7;qcom;sv_SE;164094539)
您可以找到更多here。
-
不要关闭 DevTools。刷新页面。
注意:有browser extensions 可以做到这一点。
查看this tutorial,了解如何在其他浏览器上执行此操作。
-
按 Ctrl+F,然后搜索“hd_profile_pic_url_info”。
-
复制“url”和“width”之间的URL。很长,请仔细看。 (它位于 JSON 中的 user.hd_profile_pic_url_info.url 下。)
注意:像this one 这样的扩展将使这部分变得更加容易。
现在您有了全分辨率的个人资料照片。 :)
更新:终于开始编写一个函数来获取这个 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 帐户。