Issue
a few days ago i was able to fetch inta profile pic in my android app by remove vp/ from the pic URL and change the resolution from s150x150 to s720x720 for exp ,and it worked fine but now i still get "invalid url signature" , so i think instagram has added signature to their url ,I usually remove the parte from vp/ to /t51 in the pic URL... like this
https://scontent-mxp1-1.cdninstagram.com/vp/xxxxxxxx/t51....jpg
but it doesn't work !!
I don't know what's happened with instagram,so can someone help meto find a solution for this problem? Or an alternate method . Thanks
Solution
Here's how to do it as of May 2020 July 2022 without an external website like https://www.instadp.com/. Programs can also use this API method.
First, make sure you are logged into an Instagram account on the browser that you want to do this.
Enter a username in place of "usernamehere" in this URL:
https://www.instagram.com/api/v1/users/web_profile_info/?username=usernamehere
Visit the URL. You will most likely see
{"message": "useragent mismatch", "status": "fail"}
. If you do, perform the following steps:If you are in Chrome, press F12 or Ctrl+Shift+I or Ctrl+Shift+J to open DevTools.
In the bottom draw (where you see "Console", "What's New", Network conditions"), click "Network conditions".
Under "User agent", uncheck "Select automatically".
Select "Custom...", and paste an Instagram mobile user agent into the box, like this one:
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)
You can find more here.
Do not close DevTools. Refresh the page.
Note: there are browser extensions that can do this.
Check this tutorial for how to do this on other browsers.
Copy the number after the first
"id":
near the top of the page. This is the userID. (It is also located underdata.user.id
in the JSON.)Paste the number in this URL in place of "numberhere"
https://i.instagram.com/api/v1/users/numberhere/info/
Press Ctrl+F, and search for "hd_profile_pic_url_info".
Copy the URL between "url" and "width". It's a long one, so look carefully. (It is located under
user.hd_profile_pic_url_info.url
in the JSON.)
Note: extensions like this one will make this part so much easier.
Paste the URL in the address bar, but don't press Enter.
Look for all instances of "\u0026" in the URL. There should be about 3 of them, in the second half of the URL. These are the JavaScript codes for "&", but they won't work in an address bar URL (you will see
Bad URL timestamp
if you press Enter). Replace them all with "&".Visit the URL.
Now you have your full-resolution profile picture. :)
UPDATE: Finally got round to writing a function to get this URL. You can use this in your browser, instead of having to go through all those steps.
async function fetchIGProfilePic(input) {
if (!/^https?:\/\/(.+.)?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://i.instagram.com/api/v1/users/web_profile_info/?username=' + input);
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.data.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.
In your browser, press F12 to open the console, then paste the script in. You put the username in the bottom brackets, then press Enter, and it retrieves the URL in the console. Make sure you are on https://i.instagram.com/api/v1/ and logged into an Instagram account when you run the script.
Answered By - SUM1
Answer Checked By - Mary Flores (JavaFixing Volunteer)