Giter Site home page Giter Site logo

Retrieving messages that contain reels: "Use the latest version of the Instagram app to see this reel" about instagram-private-api HOT 7 CLOSED

continue47 avatar continue47 commented on May 25, 2024
Retrieving messages that contain reels: "Use the latest version of the Instagram app to see this reel"

from instagram-private-api.

Comments (7)

continue47 avatar continue47 commented on May 25, 2024 1

Thank you @1alind that worked!

Here's an updated code that others might help others:

let igUsername = "";
let igPassword = "";
const { IgApiClient } = require("instagram-private-api");
const axios = require("axios"); // node
async function getLatestPrivateMessages(username, password) {
  const ig = new IgApiClient();

  // Login to Instagram
  ig.state.generateDevice(username);
  await ig.account.login(username, password);

  // Get the current user's inbox
  const inbox = ig.feed.directInbox();
  const threads = await inbox.items();

  // Iterate over the threads and fetch messages
  for (const thread of threads) {
    const { thread_id } = thread;
    const threadFeed = ig.feed.directThread({ thread_id });
    const messages = await threadFeed.items();
    // Process the messages
    for (const message of messages) {
      console.log(message);
      let h = {
        accept: "*/*",
        "accept-language": "en-US,en;q=0.9",
        "sec-ch-ua": '" Not A;Brand";v="99", "Chromium";v="102"',
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": '"Linux"',
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "same-site",
        "x-asbd-id": "198387",
        "x-ig-app-id": "936619743392459",
        "x-ig-www-claim":
          "hmac.AR2vqJv-rMUJZ0y3MD6rTCGpFTZHRY8OD0gGoEPuHcCI9jtN",
        cookie:
          'INSTA COOKIE',
        Referer: "https://www.instagram.com/",
        "Referrer-Policy": "strict-origin-when-cross-origin",
      };
      const response = await axios.get(
        "https://i.instagram.com/api/v1/direct_v2/threads/" +
          thread_id +
          "/get_items/?item_ids=%5B%22" +
          message.item_id +
          "%22%5D&original_message_client_contexts=%5B%22" +
          message.client_context +
          "%22%5D",
        {
          headers: h,
          body: null,
          method: "GET",
        }
      );
      console.log(response.data.items);
      if (response.data.items[0].item_type == "clip") {
        console.log(response.data.items[0].clip.clip);
      }
    }
  }
}

// Usage
getLatestPrivateMessages(igUsername, igPassword).catch(console.error);

from instagram-private-api.

1alind avatar 1alind commented on May 25, 2024

i use this
`let h = JSON.parse(fs.readFileSync('./files/h' + uid + '.json', 'utf8'));

    const response = await axios.get("https://i.instagram.com/api/v1/direct_v2/threads/" + m.message.thread_id + "/get_items/?item_ids=%5B%22" + m.message.item_id + "%22%5D&original_message_client_contexts=%5B%22" + m.message.client_context + "%22%5D", {
      headers: h,
      body: null,
      method: "GET"
    });

var link = response.data.items[0].clip.clip.video_versions[0].url;
`

the ( h ) is cookies file from a browser session that i get and add manually ti file since reels are available in browsers ig u can use that and it works fine for me.. just remember to save the session when u login in browser.should be something like this:

{ "accept": "*/*", "accept-language": "en-US,en;q=0.9", "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"102\"", "sec-ch-ua-mobile": "?0", "sec-ch-ua-platform": "\"Linux\"", "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-site", "x-asbd-id": "198387", "x-ig-app-id": "936619743392459", "x-ig-www-claim": "hmac.AR2vqJv-rMUJZ0y3MD6rTCGpFTZHRY8OD0gGoEPuHcCI9jtN", "cookie": "mid=something; ig_did=something; ig_nrcb=1; csrftoken=something; ds_user_id=something; sessionid=something; shbid=\"something\\something\\something\"; shbts=\"something\\something\\something:something\"; rur=\"RVA\\something\\something:something\"", "Referer": "https://www.instagram.com/", "Referrer-Policy": "strict-origin-when-cross-origin" }
hope that helps :)

from instagram-private-api.

diragb avatar diragb commented on May 25, 2024

The solution is no longer working, this issue should be reopened @continue47.

from instagram-private-api.

continue47 avatar continue47 commented on May 25, 2024

@diragb
It's still working for me. Can you share more info about what's not working, what kind of error message do you get, and so on?

Make sure to copy your cookie from instagram into the cookie header in the code (use the developer tools in the browser to go to the network tab and grab the cookie from a request).

from instagram-private-api.

diragb avatar diragb commented on May 25, 2024

How long will the cookie last before we need to update the code @continue47 - any ideas?

from instagram-private-api.

diragb avatar diragb commented on May 25, 2024

For future reference, I'm using this function:

const ig = new IgApiClient()

// Login user and do your stuff..

const getInstagramHeaders = async () => {
  const response = await axios.get('https://www.instagram.com/apple/')
  const html = response.data as string
  const CSRFToken = html.split('csrf_token')[1].split('\\"')[2]
  const IGAppID = html.split('X-IG-App-ID')[1].split(',')[0].replaceAll('"', '').replace(':', '')
  return {
      ...response.headers,
      'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) 20100101 Firefox/103.0',
      'Accept': '*/*',
      'Accept-Language': 'en,en-US;q=0.3',
      'X-Csrftoken': CSRFToken,
      'X-IG-App-ID': IGAppID,
      'X-ASBD-ID': '198337',
      'X-IG-WWW-Claim': 'hmac.AR2vqJv-rMUJZ0y3MD6rTCGpFTZHRY8OD0gGoEPuHcCI9jtN',
      'Origin': 'https://www.instagram.com',
      'DNT': '1',
      'Alt-Used': 'i.instagram.com',
      'Connection': 'keep-alive',
      'Referer': 'https://www.instagram.com/',
      'Referrer-Policy': 'strict-origin-when-cross-origin',
      'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="102"',
      'sec-ch-ua-mobile': '?0',
      'sec-ch-ua-platform': '"Linux"',
      'Sec-Fetch-Dest': 'empty',
      'Sec-Fetch-Mode': 'cors',
      'Sec-Fetch-Site': 'same-site',
      'Sec-GPC': '1',
      'Cookie': ig.state.cookieJar.getCookieString('https://www.instagram.com')
  }
}

from instagram-private-api.

continue47 avatar continue47 commented on May 25, 2024

I don't know how much the cookie lasts, it doesn't need to last that long for my use case.

from instagram-private-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.