Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zhongdet opened this issue Aug 24, 2024 · 17 comments
Open

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

zhongdet opened this issue Aug 24, 2024 · 17 comments

Comments

@zhongdet
Copy link

zhongdet commented Aug 24, 2024

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
Copy link
Owner

Nerixyz commented Aug 24, 2024

You still need to connect:

// 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: '...',
},
});

@zhongdet
Copy link
Author

zhongdet commented Aug 25, 2024

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
Copy link
Owner

Nerixyz commented Aug 25, 2024

You need to update your dependencies: #117.

@zhongdet
Copy link
Author

zhongdet commented Aug 25, 2024

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
Copy link
Owner

Nerixyz commented Aug 25, 2024

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

@zhongdet
Copy link
Author

zhongdet commented Aug 25, 2024

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
Copy link

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
Copy link
Author

zhongdet commented Aug 27, 2024

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
Copy link

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
Copy link
Owner

Nerixyz commented Aug 27, 2024

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
Copy link
Author

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

@eslam2511
Copy link

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
Copy link

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 zhongdet changed the title I need help, my code is not working TypeError: Cannot read properties of undefined (reading 'sessionid') Aug 27, 2024
@zhongdet
Copy link
Author

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
Copy link

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

@OpenSaned
Copy link

Any updates on this?

@OpenSaned
Copy link

I found a solution, by running ig.state.updateAuthorization() before connecting the Realtime Client fixed my problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants