dilame / instagram-private-api

NodeJS Instagram private API SDK. Written in TypeScript.
MIT License
5.99k stars 1.14k forks source link

`ig.feed.reelsMedia` retrieves stories instead of reels #1728

Open vandrieu opened 1 year ago

vandrieu commented 1 year ago

Requirements

Description

Imagine a user who published 2 recent stories and 5 reels.

Example with natgeo:

1 recent story:

Capture d’écran 2023-10-17 à 17 03 25

Lots of reels:

Capture d’écran 2023-10-17 à 17 03 37

Code

import 'dotenv/config';
import { IgApiClient, ReelsMediaFeedResponseItem, UserStoryFeedResponseItemsItem } from 'instagram-private-api';

async function main() {
  console.log("----- INIT/AUTH")
  const ig = new IgApiClient()
  ig.state.generateDevice(process.env.IG_USERNAME!);
  await ig.account.login(process.env.IG_USERNAME!, process.env.IG_PASSWORD!);

  console.log("----- SEARCH USER")
  const targetUser = await ig.user.searchExact("natgeo");

  console.log("----- FETCH STORIES")
  const userStoryFeed = ig.feed.userStory(targetUser.pk);
  const stories = await userStoryFeed.items();
  console.log("🟢", `Found ${stories.length} stories:`)
  console.log("🟢", stories.map(getMediaUrl))

  console.log("----- FETCH REELS")
  const reelsFeed = ig.feed.reelsMedia({ userIds: [targetUser.pk] });
  const reels = await reelsFeed.items();
  console.log("🟢", `Found ${reels.length} reels:`)
  console.log("🟢", reels.map(getMediaUrl))

}
main()

function getMediaUrl(item: UserStoryFeedResponseItemsItem | ReelsMediaFeedResponseItem) {
  if (item.video_versions) {
    return item.video_versions[0].url
  } else {
    return item.image_versions2.candidates[0].url
  }
}

Output

----- INIT/AUTH
  ig:state Could not find ds_user_id +0ms
  ig:request Requesting POST /api/v1/qe/sync/ +0ms
  ig:request Requesting POST /api/v1/accounts/login/ +354ms
----- SEARCH USER
  ig:request Requesting GET /api/v1/users/search/ +3s
----- FETCH STORIES
  ig:request Requesting GET /api/v1/feed/user/787132/story/ +516ms
🟢 Found 1 stories:
🟢 [
  'https://scontent-cdg4-2.cdninstagram.com/v/t51.2885-15/392891143_3631602433827303_8631248491435106258_n.jpg?se=8&stp=dst-jpg_e35&efg=eyJ2ZW5jb2RlX3RhZyI6ImltYWdlX3VybGdlbi44Mjh4MTQ3Mi5zZHIifQ&_nc_ht=scontent-cdg4-2.cdninstagram.com&_nc_cat=1&_nc_ohc=SVkWxTkU1MsAX9Nre9R&edm=ALCvFkgBAAAA&ccb=7-5&ig_cache_key=MzIxNTEwNjMwMjk3OTg0OTIwNA%3D%3D.2-ccb7-5&oh=00_AfAJ5-toT5jyOAArW7XaRwq3thsHS3rOUZdfGobli-CSGw&oe=6530204D&_nc_sid=6d62aa'
]
----- FETCH REELS
  ig:request Requesting POST /api/v1/feed/reels_media/ +270ms
🟢 Found 1 reels:
🟢 [
  'https://scontent-cdg4-2.cdninstagram.com/v/t51.2885-15/392891143_3631602433827303_8631248491435106258_n.jpg?se=8&stp=dst-jpg_e35&efg=eyJ2ZW5jb2RlX3RhZyI6ImltYWdlX3VybGdlbi44Mjh4MTQ3Mi5zZHIifQ&_nc_ht=scontent-cdg4-2.cdninstagram.com&_nc_cat=1&_nc_ohc=SVkWxTkU1MsAX9Nre9R&edm=ANmP7GQBAAAA&ccb=7-5&ig_cache_key=MzIxNTEwNjMwMjk3OTg0OTIwNA%3D%3D.2-ccb7-5&oh=00_AfDsjRul1ZnljaOU_P3fH0yoJiCBx6wySb_ogap2snUtvA&oe=6530204D&_nc_sid=982cc7'
]

Even if the end of the URL changes a little bit, both images are the same. The reel is not a reel. Both images are the same and unique story image.

How can I retrieve netgeo's reels?

NickCis commented 11 months ago

You can find more info in #1308 . In Instagram Terms Reels are Stories, and Clips are Reels. Getting Reels isn't implemented by the library, I've written a PR that implemented it some time ago, but it was never merged. I believe that this library is kind of dead and the maintainers have started with a new library but it's closed source.