fixed more errors with instagram

This commit is contained in:
Denis Utkin 2025-04-27 15:45:53 +02:00
parent 55aab2aff2
commit f3a57b33d5

View File

@ -136,21 +136,26 @@ export default function instagram(obj) {
} }
async function requestHTML(id, cookie) { async function requestHTML(id, cookie) {
try {
const data = await fetch(`https://www.instagram.com/p/${id}/embed/captioned/`, { const data = await fetch(`https://www.instagram.com/p/${id}/embed/captioned/`, {
headers: { headers: {
...embedHeaders, ...embedHeaders,
cookie cookie
}, },
dispatcher dispatcher
}).then(r => r.text()).catch(() => {}); }).then(r => r.text()).catch(() => {
});
let embedData = JSON.parse(data?.match(/"init",\[\],\[(.*?)\]\],/)[1]); let embedData = JSON.parse(data?.match(/"init",\[\],\[(.*?)\]\],/)[1]);
if (!embedData || !embedData?.contextJSON) return false; if (!embedData || !embedData?.contextJSON) return false;
embedData = JSON.parse(embedData.contextJSON); embedData = JSON.parse(embedData.contextJSON);
return embedData; return embedData;
}catch {
return null;
}
} }
async function getGQLParams(id, cookie) { async function getGQLParams(id, cookie) {
@ -213,6 +218,7 @@ export default function instagram(obj) {
} }
async function requestGQL(id, cookie) { async function requestGQL(id, cookie) {
try{
const { headers, body } = await getGQLParams(id, cookie); const { headers, body } = await getGQLParams(id, cookie);
const req = await fetch('https://www.instagram.com/graphql/query', { const req = await fetch('https://www.instagram.com/graphql/query', {
@ -246,6 +252,10 @@ export default function instagram(obj) {
.catch(() => null) .catch(() => null)
}; };
} }
catch {
return null;
}
}
async function getErrorContext(id) { async function getErrorContext(id) {
try { try {