Nerixyz / instagram_mqtt

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

Examples not working #11

Closed softwareninja closed 4 years ago

softwareninja commented 4 years ago

I tried to run the push example.

  1. I cloned the repository and installed dependencies.
  2. Created .env file (which contains my instagram id and password) in root and examples folders.
  3. Installed ts-node and added a new script in package.json. "push": "ts-node examples/push.example"
  4. Run npm run push

I get following error:

(node:60944) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at FbnsDeviceAuth.read (/Users/dev/Downloads/instagram_mqtt-master/src/fbns/fbns.device-auth.ts:36:49)
    at Object.onImport (/Users/dev/Downloads/instagram_mqtt-master/src/extend.ts:60:83)
    at IgApiClientExt.importState (/Users/dev/Downloads/instagram_mqtt-master/src/extend.ts:29:28)
(node:60944) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:60944) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Can anyone help me with this issue please?

Nerixyz commented 4 years ago

This should work. Try to delete the state.json and run the example. Check if the state.json constains fbns. Then you can run it again an it should read the values from fbns.

softwareninja commented 4 years ago

Removing state.json and running the command again, I got 400 error at login. Do I have to use api token or something similar for authentication instead of username and password?

Nerixyz commented 4 years ago

Are username and password set?

softwareninja commented 4 years ago

Yes.

IG_USERNAME=...
IG_PASSWORD=...
Nerixyz commented 4 years ago

Is it set at runtime? If so, what's the error you're getting?

softwareninja commented 4 years ago
(node:63966) UnhandledPromiseRejectionWarning: IgCheckpointError: POST /api/v1/accounts/login/ - 400 Bad Request; challenge_required
    at Request.handleResponseError (/Users/dev/Downloads/instagram_mqtt-master/node_modules/instagram-private-api/src/core/request.ts:143:16)
    at Request.send (/Users/dev/Downloads/instagram_mqtt-master/node_modules/instagram-private-api/src/core/request.ts:78:24)
(node:63966) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:63966) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Nerixyz commented 4 years ago

https://github.com/dilame/instagram-private-api/blob/master/examples/checkpoint.example.ts This should help.

softwareninja commented 4 years ago

Hi @Nerixyz That was helpful. I was able to pass the challenge but now I have:

error IgCookieNotFoundError: Cookie "ds_user_id" not found
    at State.extractCookieValue (/Users/dev/Downloads/instagram_mqtt-master/node_modules/instagram-private-api/src/core/state.ts:185:13)
    at State.get cookieUserId [as cookieUserId] (/Users/dev/Downloads/instagram_mqtt-master/node_modules/instagram-private-api/src/core/state.ts:166:17)
    at FbnsClient.sendPushRegister (/Users/dev/Downloads/instagram_mqtt-master/src/fbns/fbns.client.ts:375:38)
    at FbnsClient.handleMessage (/Users/dev/Downloads/instagram_mqtt-master/src/fbns/fbns.client.ts:326:32)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Do I need to run this example on browser where cookies are supported?

Nerixyz commented 4 years ago

There's something wrong with your state. Make sure it gets loaded properly (e.g. set a breakpoint before the fbns.connect() call and inspect ig.state.cookieJar which should contain ds_user_id). If this doesn't contain the cookie open the state file and search for the cookie. If it isn't there delete the file and log back in.)

softwareninja commented 4 years ago

I deleted the state.json and tried to login several times. Every time I got challenge_required error.

I need this example running eventually on my angular app. Is there any way to get this integrated on Angular app? Is that even possible?

Nerixyz commented 4 years ago

You're getting this error brecause you're essentially using a new device to login. However your state (and thus your cookies) do not get saved/loaded. If your angular app is running inside of a browser, this won't work as raw TLS sockets are not allowed there. You'd have to create a bridge over WebSockets for example.

bvanhou commented 4 years ago

Do you have any idea on how you would bridge the two? @Nerixyz

Do you think this could work?

https://github.com/JetClosing/graphql-lambda-websocket
Nerixyz commented 4 years ago

Do you have any idea on how you would bridge the two?

This could be achieved through web-sockets. You'd then have to create your own "message-format".