Nerixyz / instagram_mqtt

Realtime and Push Notification (FBNS) support for the instagram-private-api
MIT License
250 stars 50 forks source link

TypeError: Cannot read properties of undefined (reading 'sessionid') #120

Open zhongdet opened 3 weeks ago

zhongdet commented 3 weeks ago

Hello,II'm a beginner in learning programming and I'm having some problems, but I don't know what I'm doing wrong If you are free, can you take a look at it for me? this is my code↓↓↓

import { IgApiClientRealtime, withRealtime, withFbnsAndRealtime, withFbns } from 'instagram_mqtt'
import { IgApiClient } from "instagram-private-api";

const ig = withFbnsAndRealtime(new IgApiClient());

const IgUsername = 'username';
const IgPassword = 'password';

(async () => {
    ig.state.generateDevice(IgUsername);

    const auth = await ig.account.login(IgUsername, IgPassword);
    console.log('login processed')

    ig.realtime.on('message', (e) => console.log(e))

    setInterval(() => {
        console.log("1sec")
    }, 1000)

})();

It will only print "1sec" repeatly, but nothing happens when the message is received thanks for anyone who help me

Nerixyz commented 3 weeks ago

You still need to connect:

https://github.com/Nerixyz/instagram_mqtt/blob/f2672ac2c1167859e4fcc3a2d0f6a4660a33250b/examples/realtime.example.ts#L35-L67

zhongdet commented 3 weeks ago

If I use ig.realtime.connect, the console print out error↓↓↓

IgCookieNotFoundError: Cookie "sessionid" not found
    at State.extractCookieValue (c:\Users\user\Desktop\coding\practice\messengram\node_modules\instagram-private-api\src\core\state.ts:210:13)
    at RealtimeClient.constructConnection (c:\Users\user\Desktop\coding\practice\messengram\node_modules\instagram_mqtt\src\realtime\realtime.client.ts:70:87)
    at MQTToTClient.payloadProvider [as connectPayloadProvider] (c:\Users\user\Desktop\coding\practice\messengram\node_modules\instagram_mqtt\src\realtime\realtime.client.ts:121:18)
    at MQTToTClient.connect (c:\Users\user\Desktop\coding\practice\messengram\node_modules\instagram_mqtt\src\mqttot\mqttot.client.ts:91:40)
    at c:\Users\user\Desktop\coding\practice\messengram\node_modules\instagram_mqtt\src\realtime\realtime.client.ts:176:21
    at new Promise (<anonymous>)
    at RealtimeClient.connect (c:\Users\user\Desktop\coding\practice\messengram\node_modules\instagram_mqtt\src\realtime\realtime.client.ts:163:14)
    at RealtimeClient.wrapper (c:\Users\user\Desktop\coding\practice\messengram\node_modules\instagram_mqtt\src\realtime\mixins\mixin.ts:35:33)
    at RealtimeClient.wrapper (c:\Users\user\Desktop\coding\practice\messengram\node_modules\instagram_mqtt\src\realtime\mixins\mixin.ts:35:33)
    at c:\Users\user\Desktop\coding\practice\messengram\main.ts:22:23

I can get my full_name by ((await ig.account.currentUser()).full_name) ,so I think I have logged in

Nerixyz commented 3 weeks ago

You need to update your dependencies: https://github.com/Nerixyz/instagram_mqtt/issues/117.

zhongdet commented 3 weeks ago

I checked the dependencies, the version of insatgram_mqtt was already 1.2.3

  "dependencies": {
    "instagram_mqtt": "^1.2.3",
    "instagram-private-api": "^1.46.1",
  },

And if I use ig.state.parsedAuthorization.sessionid, the console↓↓↓

TypeError: Cannot read properties of undefined (reading 'sessionid')
    at RealtimeClient.constructConnection (c:\Users\user\Desktop\coding\practice\messengram\node_modules\instagram_mqtt\src\realtime\realtime.client.ts:70:69)
    at MQTToTClient.payloadProvider [as connectPayloadProvider] (c:\Users\user\Desktop\coding\practice\messengram\node_modules\instagram_mqtt\src\realtime\realtime.client.ts:122:18)
    at MQTToTClient.connect (c:\Users\user\Desktop\coding\practice\messengram\node_modules\instagram_mqtt\src\mqttot\mqttot.client.ts:91:40)
    at c:\Users\user\Desktop\coding\practice\messengram\node_modules\instagram_mqtt\src\realtime\realtime.client.ts:177:13
    at new Promise (<anonymous>)
    at RealtimeClient.connect (c:\Users\user\Desktop\coding\practice\messengram\node_modules\instagram_mqtt\src\realtime\realtime.client.ts:164:10)
    at RealtimeClient.wrapper (c:\Users\user\Desktop\coding\practice\messengram\node_modules\instagram_mqtt\src\realtime\mixins\mixin.ts:35:33)
    at RealtimeClient.wrapper (c:\Users\user\Desktop\coding\practice\messengram\node_modules\instagram_mqtt\src\realtime\mixins\mixin.ts:35:33)
    at c:\Users\user\Desktop\coding\practice\messengram\main.ts:21:23
    at step (c:\Users\user\Desktop\coding\practice\messengram\main.ts:33:23)
    at Object.next (c:\Users\user\Desktop\coding\practice\messengram\main.ts:14:53)
    at fulfilled (c:\Users\user\Desktop\coding\practice\messengram\main.ts:5:58)
Nerixyz commented 2 weeks ago

Are you sure, you're logged in before you access ig.state.parsedAuthorization.sessionid?

zhongdet commented 2 weeks ago

I think I do↓↓↓

import { withRealtime } from 'instagram_mqtt'
import { IgApiClient } from "instagram-private-api";

const ig = withRealtime(new IgApiClient());

const IgUsername = 'username';
const IgPassword = 'password';

(async () => {
    ig.state.generateDevice(IgUsername);

    await ig.account.login(IgUsername, IgPassword);
    const IgFull_name = ((await ig.account.currentUser()).full_name)
    console.log(`login processed[${IgUsername}], (${IgFull_name})`);

    console.log(ig.state.parsedAuthorization.sessionid)

    ig.realtime.on('message', (e) => console.log(e.message))
    ig.realtime.on('error', console.error)
    ig.realtime.on('close', () => console.error("RealtimeClient closed"))
    // connect 
    // this will resolve once all initial subscriptions have been sent 
    await ig.realtime.connect({
        // optional 
        // graphQlSubs: [
        //     // these are some subscriptions 
        //     GraphQLSubscriptions.getAppPresenceSubscription(),
        //     GraphQLSubscriptions.getZeroProvisionSubscription(ig.state.phoneId),
        //     GraphQLSubscriptions.getDirectStatusSubscription(),
        //     GraphQLSubscriptions.getDirectTypingSubscription(ig.state.cookieUserId),
        //     GraphQLSubscriptions.getAsyncAdSubscription(ig.state.cookieUserId),
        // ],
        // // optional 
        // skywalkerSubs: [
        //     SkywalkerSubscriptions.directSub(ig.state.cookieUserId),
        //     SkywalkerSubscriptions.liveSub(ig.state.cookieUserId),
        // ],
        // optional 
        // this enables you to get direct messages 
        // irisData: await ig.feed.directInbox().request(),
        // optional 
        // in here you can change connect options 
        // available are all properties defined in MQTToTConnectionClientInfo 
        // connectOverrides: {},

        // optional 
        // use this proxy 
        // socksOptions: {
        //     type: 5,
        //     port: 12345,
        //     host: '...',
        // },
    });

    setInterval(() => {
        console.log("1sec")
    }, 1000)

})();
eslam2511 commented 2 weeks ago

I think I do↓↓↓

import { withRealtime } from 'instagram_mqtt'
import { IgApiClient } from "instagram-private-api";

const ig = withRealtime(new IgApiClient());

const IgUsername = 'username';
const IgPassword = 'password';

(async () => {
    ig.state.generateDevice(IgUsername);

    await ig.account.login(IgUsername, IgPassword);
    const IgFull_name = ((await ig.account.currentUser()).full_name)
    console.log(`login processed[${IgUsername}], (${IgFull_name})`);

    console.log(ig.state.parsedAuthorization.sessionid)

    ig.realtime.on('message', (e) => console.log(e.message))
    ig.realtime.on('error', console.error)
    ig.realtime.on('close', () => console.error("RealtimeClient closed"))
    // connect 
    // this will resolve once all initial subscriptions have been sent 
    await ig.realtime.connect({
        // optional 
        // graphQlSubs: [
        //     // these are some subscriptions 
        //     GraphQLSubscriptions.getAppPresenceSubscription(),
        //     GraphQLSubscriptions.getZeroProvisionSubscription(ig.state.phoneId),
        //     GraphQLSubscriptions.getDirectStatusSubscription(),
        //     GraphQLSubscriptions.getDirectTypingSubscription(ig.state.cookieUserId),
        //     GraphQLSubscriptions.getAsyncAdSubscription(ig.state.cookieUserId),
        // ],
        // // optional 
        // skywalkerSubs: [
        //     SkywalkerSubscriptions.directSub(ig.state.cookieUserId),
        //     SkywalkerSubscriptions.liveSub(ig.state.cookieUserId),
        // ],
        // optional 
        // this enables you to get direct messages 
        // irisData: await ig.feed.directInbox().request(),
        // optional 
        // in here you can change connect options 
        // available are all properties defined in MQTToTConnectionClientInfo 
        // connectOverrides: {},

        // optional 
        // use this proxy 
        // socksOptions: {
        //     type: 5,
        //     port: 12345,
        //     host: '...',
        // },
    });

    setInterval(() => {
        console.log("1sec")
    }, 1000)

})();

I have the same issue did you find any solution ?

zhongdet commented 2 weeks ago

I have the same issue did you find any solution ?

I haven't found a solution for this package, but I found another node package witch can do the same thing: https://github.com/Debanjan-San/node-ig-framework The strange thing is the package seems to also use instagram_mqtt and ig.realtime.connect() , but it works well, and I don't know why

eslam2511 commented 2 weeks ago

I have the same issue did you find any solution ?

I haven't found a solution for this package, but I found another node package witch can do the same thing: https://github.com/Debanjan-San/node-ig-framework The strange thing is the package seems to also use instagram_mqtt and ig.realtime.connect() , but it works well, and I don't know why

if you look at the dependencies you will notice that he has his own version of the instagram_mqtt that he modified

Nerixyz commented 2 weeks ago

And if I use ig.state.parsedAuthorization.sessionid, the console↓↓↓

TypeError: Cannot read properties of undefined (reading 'sessionid')
[...]

This indicates that parsedAuthorization is undefined (i.e. it's not parsed). That's not a bug with this library, but with instagram-private-api.

I haven't found a solution for this package, but I found another node package witch can do the same thing: Debanjan-San/node-ig-framework The strange thing is the package seems to also use instagram_mqtt and ig.realtime.connect() , but it works well, and I don't know why

The reason this "works" is that they're only trying the parsedAuthorization. If that's undefined, it will fail too, and if the sessionid is undefined, it will silently fail by using sessionid=undefined as the password.

zhongdet commented 2 weeks ago

So, is there a way to continue using ig.realtime.connect() of your instagram_mqtt ?

eslam2511 commented 2 weeks ago

So, is there a way to continue using ig.realtime.connect() of your instagram_mqtt ?

I think Instagram private api need to be fixed

eslam2511 commented 2 weeks ago

And if I use ig.state.parsedAuthorization.sessionid, the console↓↓↓

TypeError: Cannot read properties of undefined (reading 'sessionid')
[...]

This indicates that parsedAuthorization is undefined (i.e. it's not parsed). That's not a bug with this library, but with instagram-private-api.

I haven't found a solution for this package, but I found another node package witch can do the same thing: Debanjan-San/node-ig-framework The strange thing is the package seems to also use instagram_mqtt and ig.realtime.connect() , but it works well, and I don't know why

The reason this "works" is that they're only trying the parsedAuthorization. If that's undefined, it will fail too, and if the sessionid is undefined, it will silently fail by using sessionid=undefined as the password.

I fixed it by decoding and parsing the authorization by my self but now I get this error


      throw er; // Unhandled 'error' event
      ^

Error: 405295600C7C0000:error:0A000458:SSL routines:ssl3_read_bytes:tlsv1 unrecognized name:ssl/record/rec_layer_s3.c:1590:SSL alert number 112

Emitted 'error' event on TLSSocket instance at:
    at emitErrorNT (node:internal/streams/destroy:169:8)
    at emitErrorCloseNT (node:internal/streams/destroy:128:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  library: 'SSL routines',
  reason: 'tlsv1 unrecognized name',
  code: 'ERR_SSL_TLSV1_UNRECOGNIZED_NAME'
}

Node.js v20.12.2 
zhongdet commented 2 weeks ago

if you look at the dependencies you will notice that he has his own version of the instagram_mqtt that he modified

Can changing the dependencies of this library to node-ig-framework solve this problem?

eslam2511 commented 2 weeks ago

if you look at the dependencies you will notice that he has his own version of the instagram_mqtt that he modified

Can changing the dependencies of this library to node-ig-framework solve this problem?

No it didn't for me