Instagram-private-api: Getting all direct threads with all messages

Created on 5 Jul 2019  路  8Comments  路  Source: dilame/instagram-private-api

Hello!
I would like to get all direct threads with all messages, but when I use

const inboxFeed = ig.feed.directInbox();
const threads = await inboxFeed.items();

it returns only 10 last items in each thread. How can I get all messages for some thread or for all threads?

Most helpful comment

Dont know why I cant pass thread_id only as a parameter. But seems I MUST pass it as parameter AND as property.

As you can see here, you have to pass in an object not a string (consider using Typescript).
The object has to look like this: { thread_id: string, oldest_cursor?: string }.

All 8 comments

You'll have to call inboxFeed.items() multiple times to get all items.
In order to get messages you'll have to use the ig.feed.directThread(thread)-feed. You can just use the thread you got in the threads.

isMoreAvailable() doesn't work for me. And I did manually :)
+Go to instagram-private-api lib file where you installed: something like=> 'yourpath/instagram-private-api\node_modules\instagram-private-api\dist\feeds\direct-inbox.feed.js'
+Change thread_message_limit: 10 to what you want

isMoreAvailable() doesn't work for me.

Could you show the code on how you got to this conclusion?

+Change thread_message_limit: 10 to what you want

This changes the messages in the thread that are sent.

isMoreAvaiable() is giving false for threadFeed.

const chatsFeed = igClient.feed.directInbox();
exports.getChatList = function () {
  return new Promise((resolve, reject) => {
    chatsFeed.items().then(resolve).catch(reject);
  });
};

let threadFeed;
exports.getChat = function (chatId) {
  return new Promise((resolve, reject) => {
    chatsFeed.cursor = undefined;
    chatsFeed.items().then((chats)=>{
      const thread = chats.find(chat => chat.thread_id === chatId);
      threadFeed = igClient.feed.directThread(thread);
      const isMoreAvailable = threadFeed.isMoreAvailable();
      console.log(isMoreAvailable); // HERE IS SHOWS FALSE :(
      if (isMoreAvailable) {
        threadFeed.items().then((messages) => {
          thread.items.concat(messages);
        });
      } else {
        resolve(thread);
      }
    }).catch(reject);
  });

I got an error when try to get thread feed by id. I also tried pass thread_id_v2 but got the same error.

let directFeed = await ig.feed.directInbox()
let chats = await directFeed.items()

// This is two types of thread id in this chat
let thread_id = chats[0].thread_id;
let thread_id_v2 = chats[0].thread_v2_id;

let threadFeed = await ig.feed.directThread(thread_id)

// And now I got an error 
// IgNotFoundError: GET /api/v1/direct_v2/threads/undefined/?visual_message_return_type=unseen&direction=older&limit=10 - 404 Not Found; 
let thread = await threadFeed.items()

Problem resolved, i found that I need pass id directly to property like this.

let threadFeed = await ig.feed.directThread(thread_id)
threadFeed.id = thread_id

Dont know why I cant pass thread_id only as a parameter. But seems I MUST pass it as parameter AND as property.

I got an error when try to get thread feed by id. I also tried pass thread_id_v2 but got the same error.

let directFeed = await ig.feed.directInbox()
let chats = await directFeed.items()

// This is two types of thread id in this chat
let thread_id = chats[0].thread_id;
let thread_id_v2 = chats[0].thread_v2_id;

let threadFeed = await ig.feed.directThread(thread_id)

// And now I got an error 
// IgNotFoundError: GET /api/v1/direct_v2/threads/undefined/?visual_message_return_type=unseen&direction=older&limit=10 - 404 Not Found; 
let thread = await threadFeed.items()

Problem resolved, i found that I need pass id directly to property like this.

let threadFeed = await ig.feed.directThread(thread_id)
threadFeed.id = thread_id

Dont know why I cant pass thread_id only as a parameter. But seems I MUST pass it as parameter AND as property.

@Nerixyz this actually is a problem.

Dont know why I cant pass thread_id only as a parameter. But seems I MUST pass it as parameter AND as property.

As you can see here, you have to pass in an object not a string (consider using Typescript).
The object has to look like this: { thread_id: string, oldest_cursor?: string }.

Dont know why I cant pass thread_id only as a parameter. But seems I MUST pass it as parameter AND as property.

As you can see here, you have to pass in an object not a string (consider using Typescript).
The object has to look like this: { thread_id: string, oldest_cursor?: string }.

what is the good reason for passing a Pick <..> instead of separate arguments since oldest_cursor is already optional?
I'd suggest adding another constructor for initialization with thread_id string only.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sagardalal21 picture sagardalal21  路  39Comments

27RU57 picture 27RU57  路  12Comments

endquote picture endquote  路  12Comments

350d picture 350d  路  53Comments

haliliceylan picture haliliceylan  路  29Comments