mirror of
https://github.com/imputnet/cobalt.git
synced 2025-06-28 09:28:29 +00:00
fixed instagram fetch problems
This commit is contained in:
parent
2f6c61f5e4
commit
8aebb2eb24
@ -106,7 +106,7 @@ export default function instagram(obj) {
|
|||||||
return data.json();
|
return data.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getMediaId(id, { cookie, token } = {}) {
|
async function getMedia(id, { cookie, token } = {}) {
|
||||||
const oembedURL = new URL('https://i.instagram.com/api/v1/oembed/');
|
const oembedURL = new URL('https://i.instagram.com/api/v1/oembed/');
|
||||||
oembedURL.searchParams.set('url', `https://www.instagram.com/p/${id}/`);
|
oembedURL.searchParams.set('url', `https://www.instagram.com/p/${id}/`);
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ export default function instagram(obj) {
|
|||||||
dispatcher
|
dispatcher
|
||||||
}).then(r => r.json()).catch(() => {});
|
}).then(r => r.json()).catch(() => {});
|
||||||
|
|
||||||
return oembed?.media_id;
|
return oembed;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function requestMobileApi(mediaId, { cookie, token } = {}) {
|
async function requestMobileApi(mediaId, { cookie, token } = {}) {
|
||||||
@ -425,9 +425,13 @@ export default function instagram(obj) {
|
|||||||
const token = bearer?.values()?.token;
|
const token = bearer?.values()?.token;
|
||||||
|
|
||||||
// get media_id for mobile api, three methods
|
// get media_id for mobile api, three methods
|
||||||
let media_id = await getMediaId(id);
|
let media = await getMedia(id);
|
||||||
if (!media_id && token) media_id = await getMediaId(id, { token });
|
if (!media?.media_id && token) media = await getMedia(id, { token });
|
||||||
if (!media_id && cookie) media_id = await getMediaId(id, { cookie });
|
if (!media?.media_id && cookie) media = await getMedia(id, { cookie });
|
||||||
|
if(media.title.includes('Restricted')) {
|
||||||
|
return { error: "content.post.age" }
|
||||||
|
}
|
||||||
|
let media_id = media?.media_id;
|
||||||
|
|
||||||
// mobile api (bearer)
|
// mobile api (bearer)
|
||||||
if (media_id && token) data = await requestMobileApi(media_id, { token });
|
if (media_id && token) data = await requestMobileApi(media_id, { token });
|
||||||
|
Loading…
Reference in New Issue
Block a user