mifi / SimpleInstaBot

Simple Instagram bot GUI
MIT License
606 stars 87 forks source link

Unexpected token o in JSON at position 1 #125

Closed diegomustafamarino closed 2 years ago

diegomustafamarino commented 2 years ago

To Reproduce Unexpected token o in JSON at position 1

Screenshots

image

Desktop (please complete the following information):

main.075a4527.chunk.js:1 Failed to run SyntaxError: Unexpected token o in JSON at position 1 at JSON.parse () at getPageJson (C:\Users\J951F~1\AppData\Local\Temp\27HguQcbkCvsVXCIsh9XAn4f2sS\resources\app.asar\node_modules\instauto\index.js:220:17) at runMicrotasks () at processTicksAndRejections (internal/process/task_queues.js:85:5) at async navigateToUserAndGetData (C:\Users\J951F~1\AppData\Local\Temp\27HguQcbkCvsVXCIsh9XAn4f2sS\resources\app.asar\node_modules\instauto\index.js:231:20) at async Instauto (C:\Users\J951F~1\AppData\Local\Temp\27HguQcbkCvsVXCIsh9XAn4f2sS\resources\app.asar\node_modules\instauto\index.js:937:22) at async Object.initInstauto (C:\Users\J951F~1\AppData\Local\Temp\27HguQcbkCvsVXCIsh9XAn4f2sS\resources\app.asar\build\electron.js:147:14)

diegomustafamarino commented 2 years ago

another try and: main.075a4527.chunk.js:1 Failed to run Error: User not found at navigateToUserWithCheck (C:\SimpleInstaBot-win\resources\app.asar\node_modules\instauto\index.js:216:50) at processTicksAndRejections (internal/process/task_queues.js:85:5) at async navigateToUserAndGetData (C:\SimpleInstaBot-win\resources\app.asar\node_modules\instauto\index.js:239:5) at async Instauto (C:\SimpleInstaBot-win\resources\app.asar\node_modules\instauto\index.js:937:22) at async Object.initInstauto (C:\SimpleInstaBot-win\resources\app.asar\build\electron.js:147:14

mifi commented 2 years ago

Hi. Does it happen with any user or just one? Can you try to open this in your browser:

https://www.instagram.com/user.account/?__a=1
diegomustafamarino commented 2 years ago

I Just have 1 user, i'm trying to install a virtual machina with hackintosh to try it

image

Firefox < and Chrome >

diegomustafamarino commented 2 years ago

Hackintosh didn't work to: Message: User not found

mifi commented 2 years ago

It could be that Instagram has been changing some behavior regarding the ?__a=1 URLs, but only for some users. I am not able to reproduce this problem.

mifi commented 2 years ago

would be nice if you could post the full log history from SimpleInstaBot when it crashes, and I assume you're using the latest version?

diegomustafamarino commented 2 years ago

would be nice if you could post the full log history from SimpleInstaBot when it crashes, and I assume you're using the latest version?

Ok, give me a momment... Yes, lastest version.

diegomustafamarino commented 2 years ago

would be nice if you could post the full log history from SimpleInstaBot when it crashes, and I assume you're using the latest version?

Here we go:

main.21cc2732.chunk.js:1 No cookies found e @ main.21cc2732.chunk.js:1 error @ main.21cc2732.chunk.js:1 apply @ callbacks-registry.ts:45 (anonymous) @ remote.js:286 (anonymous) @ remote.js:276 emit @ events.js:203 onMessage @ init.ts:50 main.21cc2732.chunk.js:1 Setting language to English (en) main.21cc2732.chunk.js:1 Waiting 1 sec main.21cc2732.chunk.js:1 Waiting 4 sec main.21cc2732.chunk.js:1 Found language selector main.21cc2732.chunk.js:1 Already English language main.21cc2732.chunk.js:1 Waiting 2 sec main.21cc2732.chunk.js:1 No login page button, assuming we are on login form main.21cc2732.chunk.js:1 Waiting 2 sec main.21cc2732.chunk.js:1 Waiting 1 sec main.21cc2732.chunk.js:1 Waiting 11 sec main.21cc2732.chunk.js:1 Setting language to English (en) main.21cc2732.chunk.js:1 Waiting 2 sec main.21cc2732.chunk.js:1 Waiting 5 sec main.21cc2732.chunk.js:1 Found language selector main.21cc2732.chunk.js:1 Already English language main.21cc2732.chunk.js:1 Saving cookies main.21cc2732.chunk.js:1 Have followed/unfollowed 0 in the last hour main.21cc2732.chunk.js:1 Have followed/unfollowed 0 in the last 24 hours main.21cc2732.chunk.js:1 Have liked 0 images in the last 24 hours main.21cc2732.chunk.js:1 Navigating to user user main.21cc2732.chunk.js:1 Goto https://www.instagram.com/user main.21cc2732.chunk.js:1 Waiting 1 sec main.21cc2732.chunk.js:1 Failed to run Error: User not found at navigateToUserWithCheck (/Applications/Simple…stauto/index.js:216) at processTicksAndRejections (internal/process/taskqueues.js:85) at async navigateToUserAndGetData (/Applications/Simple…stauto/index.js:239) at async Instauto (/Applications/Simple…stauto/index.js:937) at async Object.initInstauto (electron.js:147) e @ main.21cc2732.chunk.js:1 error @ main.21cc2732.chunk.js:1 ot @ main.21cc2732.chunk.js:1 async function (async)
ot @ main.21cc2732.chunk.js:1 onClick @ main.21cc2732.chunk.js:1 m @ 2.883abbf7.chunk.js:2 z @ 2.883abbf7.chunk.js:2 (anonymous) @ 2.883abbf7.chunk.js:2 C @ 2.883abbf7.chunk.js:2 V @ 2.883abbf7.chunk.js:2
@ 2.883abbf7.chunk.js:2 T @ 2.883abbf7.chunk.js:2 Mr @ 2.883abbf7.chunk.js:2 le @ 2.883abbf7.chunk.js:2 Er @ 2.883abbf7.chunk.js:2 Tr @ 2.883abbf7.chunk.js:2 Vr @ 2.883abbf7.chunk.js:2 t.unstable_runWithPriority @ 2.883abbf7.chunk.js:2 Wa @ 2.883abbf7.chunk.js:2 oe @ 2.883abbf7.chunk.js:2 Sr @ 2.883abbf7.chunk.js:2 2.883abbf7.chunk.js:2 SweetAlert2: Unknown parameter "onDestroy" d @ 2.883abbf7.chunk.js:2 Xe @ 2.883abbf7.chunk.js:2 (anonymous) @ 2.883abbf7.chunk.js:2 main @ 2.883abbf7.chunk.js:2 value @ 2.883abbf7.chunk.js:2 Kt @ 2.883abbf7.chunk.js:2 (anonymous) @ 2.883abbf7.chunk.js:2 v @ 2.883abbf7.chunk.js:2 fire @ 2.883abbf7.chunk.js:2 ot @ main.21cc2732.chunk.js:1 async function (async)
ot @ main.21cc2732.chunk.js:1 onClick @ main.21cc2732.chunk.js:1 m @ 2.883abbf7.chunk.js:2 z @ 2.883abbf7.chunk.js:2 (anonymous) @ 2.883abbf7.chunk.js:2 C @ 2.883abbf7.chunk.js:2 V @ 2.883abbf7.chunk.js:2
@ 2.883abbf7.chunk.js:2 T @ 2.883abbf7.chunk.js:2 Mr @ 2.883abbf7.chunk.js:2 le @ 2.883abbf7.chunk.js:2 Er @ 2.883abbf7.chunk.js:2 Tr @ 2.883abbf7.chunk.js:2 Vr @ 2.883abbf7.chunk.js:2 t.unstable_runWithPriority @ 2.883abbf7.chunk.js:2 Wa @ 2.883abbf7.chunk.js:2 oe @ 2.883abbf7.chunk.js:2 Sr @ 2.883abbf7.chunk.js:2

diegomustafamarino commented 2 years ago

It could be that Instagram has been changing some behavior regarding the ?__a=1 URLs, but only for some users. I am not able to reproduce this problem.

It happens when i try to open the ?__a=1 of my own account when i'm logged in my own account too: image

TEXT:

for (;;);{"__ar":1,"error":1357004,"errorSummary":"Ocorreu um erro","errorDescription":"Feche e abra a janela do seu navegador novamente.","payload":null,"hsrp":{"hblp":{"consistency":{"rev":1005366256}}},"lid":"7087291162611017638"}

diegomustafamarino commented 2 years ago

It could be that Instagram has been changing some behavior regarding the ?__a=1 URLs, but only for some users. I am not able to reproduce this problem.

is there a solution? I can extract here any information you need and if you want I can share the screen on teams too or something like that

mifi commented 2 years ago

TBH I don't know why this is happening. :| Instagram seems to be sending some strange response. seems to only happen for a few people...

diegomustafamarino commented 2 years ago

TBH I don't know why this is happening. :| Instagram seems to be sending some strange response. seems to only happen for a few people...

oh, ok :/ my company insta is blocked for bot =/. No problems. Thanks!

diegomustafamarino commented 2 years ago

anyway, i'll try the lastest version

richienko commented 2 years ago

It's happening to our instance too. Account is not blocked as it's loading just fine.

Goto https://www.instagram.com/?a=1 throws same SyntaxError. Opening https://www.instagram.com/?a=1 redirects to https://www.instagram.com//?__a=1 (note the added slash)

If I try to open https://www.instagram.com//?a=1 (or https://www.instagram.com/?a=1), I get raw JSON of data of what looks like feed. With following structure (with personal data removed):

{
   "seo_category_infos":[],
   "logging_page_id":"",
   "show_suggested_profiles":false,
   "graphql":{
      "user":{
         "biography":"",
         "blocked_by_viewer":false,
         "restricted_by_viewer":null,
         "country_block":false,
         "external_url":",
         "external_url_linkshimmed":"",
         "edge_followed_by":{},
         "fbid":"",
         "followed_by_viewer":false,
         "edge_follow":{},
         "follows_viewer":false,
         "full_name":"",
         "has_ar_effects":false,
         "has_clips":true,
         "has_guides":false,
         "has_channel":false,
         "has_blocked_viewer":false,
         "highlight_reel_count":8,
         "has_requested_viewer":false,
         "hide_like_and_view_counts":false,
         "id":"",
         "is_business_account":true,
         "is_professional_account":true,
         "is_supervision_enabled":false,
         "is_guardian_of_viewer":false,
         "is_supervised_by_viewer":false,
         "is_embeds_disabled":false,
         "is_joined_recently":false,
         "business_address_json":null,
         "business_contact_method":"UNKNOWN",
         "business_email":null,
         "business_phone_number":null,
         "business_category_name":"",
         "overall_category_name":null,
         "category_enum":"",
         "category_name":"",
         "is_private":false,
         "is_verified":false,
         "edge_mutual_followed_by":{},
         "profile_pic_url":"",
         "profile_pic_url_hd":"",
         "requested_by_viewer":false,
         "should_show_category":true,
         "should_show_public_contacts":true,
         "state_controlled_media_country":null,
         "username":"",
         "connected_fb_page":null,
         "pronouns":[],
         "edge_felix_video_timeline":{},
         "edge_owner_to_timeline_media":{},
         "edge_saved_media":{},
         "edge_media_collections":{},
         "edge_related_profiles":{}
      }
   },
   "toast_content_on_load":null,
   "show_qr_modal":false,
   "show_view_shop":false
}

It seems I can't find full log so I just post screenshot here:

Screenshot 2022-04-22 at 13 54 58

diegomustafamarino commented 2 years ago

Nice. I hope someone can help us

mifi commented 2 years ago

so https://www.instagram.com/user.account/?__a=1 gives an error while https://www.instagram.com/user.account//?__a=1 (extra slash) gives the proper JSON?

diegomustafamarino commented 2 years ago

so https://www.instagram.com/user.account/?__a=1 gives an error while https://www.instagram.com/user.account//?__a=1 (extra slash) gives the proper JSON?

idk why, this link: https://www.instagram.com/user.account/?__a=1 is working here now, i'll try the bot again..

diegomustafamarino commented 2 years ago

worked fine, nice work thank u man !! i think the solution for this cases is just wait and try this links sometimes

diegomustafamarino commented 2 years ago

I will use for a month then i supply ur work thanks

richienko commented 2 years ago

I can confirm, that bot is now working, probably some bug on Twitter

tcortega commented 2 years ago

This is happening to me aswell. I'd be glad to help by providing my account if needed.

AureliusAce commented 2 years ago

Hello i have the same problem with both of my account. But i have another problem - im a total beginner in coding. From what you wrote i think i understood i have to delete "https://www.instagram.com/user.account/?__a=1" and put "https://www.instagram.com/user.account//?__a=1 (extra slash)" in where it was. But im to dumb to make it. can you please tell me, how i do it? Would be really nice. Thanks a lot for your work :)

Brozzor commented 2 years ago

Hello, I just had the same problem on 2 of my business accounts

codenamey commented 2 years ago

I tried that https://www.instagram.com/user.account/?__a=1 and it try to go "login" after i login and try that again it print like this with my browser.

for (;;);{"__ar":1,"error":1357004,"errorSummary":"Sorry, something went wrong","errorDescription":"Please try closing and re-opening your browser window.","payload":null,"hsrp":{"hblp":{"consistency":{"rev":1005611792}}},"lid":"7104412750110707038"}

I think the reason is:

2:16 AMMissing graphql in page, falling back to alternative method... and alterative is not working.

Brozzor commented 2 years ago

I tried that https://www.instagram.com/user.account/?__a=1 and it try to go "login" after i login and try that again it print like this with my browser.

for (;;);{"__ar":1,"error":1357004,"errorSummary":"Sorry, something went wrong","errorDescription":"Please try closing and re-opening your browser window.","payload":null,"hsrp":{"hblp":{"consistency":{"rev":1005611792}}},"lid":"7104412750110707038"}

I think the reason is:

2:16 AMMissing graphql in page, falling back to alternative method... and alterative is not working.

I've been racking my brain trying to figure out how to fix this problem but I can't

getitdonestudio commented 2 years ago

I think the reason is:

2:16 AMMissing graphql in page, falling back to alternative method... and alterative is not working.

Same problem here. Seems like the JSON is no longer available neither from https://www.instagram.com/user.account/?__a=1 nor https://www.instagram.com/user.account//?__a=1

Anyone having an other idea to solve this?

tcortega commented 2 years ago

Ideally we should stop relying on this unstable endpoint and find another way to recover the data the bot needs. But for that we would need @mifi 's attention xD

AureliusAce commented 2 years ago

Yes that would be great. I'm about to experiment with other bots, but this is the best I've found so far.

mifi commented 2 years ago

Basically we need to find a way to find the User ID of an account, only knowing the account's username. Previously we used methods like these: https://stackoverflow.com/questions/11796349/instagram-how-to-get-my-user-id-from-username but it seems that none of those work anymore.

can look into other bots like https://github.com/InstaPy/InstaPy how they do it

The user ID is needed for GraphQL queries.

tcortega commented 2 years ago

Basically we need to find a way to find the User ID of an account, only knowing the account's username. Previously we used methods like these: https://stackoverflow.com/questions/11796349/instagram-how-to-get-my-user-id-from-username but it seems that none of those work anymore.

can look into other bots like https://github.com/InstaPy/InstaPy how they do it

The user ID is needed for GraphQL queries.

Upon sniffing a few requests I found an endpoint that makes this possible: https://i.instagram.com/api/v1/users/web_profile_info/?username=username_here

mifi commented 2 years ago

cool! but it's giving me {"message":"useragent mismatch","status":"fail"}. not sure which user agent they are expecting...

tcortega commented 2 years ago

cool! but it's giving me {"message":"useragent mismatch","status":"fail"}. not sure which user agent they are expecting...

Seems like it requires a few extra headers in order to allow the request to passthrough. If you are using Puppeteer you could specifically intercept this request and get it's response data. Another alternative is that, it seems like the user id gets loaded at some point into the DOM

mifi commented 2 years ago

Thanks, will try that!

mifi commented 2 years ago

Oh if you can find the user ID in the Dom somewhere let me know

tcortega commented 2 years ago

Oh if you can find the user ID in the Dom somewhere let me know

You can find it by doing these two operations:

const body = document.querySelector("body").innerHTML
const userId = body.match(/profile_id":"(.*?)"/)[1]
mifi commented 2 years ago

omg it works! i intercepted the request and all the needed data is there. releasing new version

tcortega commented 2 years ago

The fix commit looks great. I would add the DOM alternative as a fallback aswell. In case any exceptions happen, and may be worth comparing how fast both these solutions perform, because it seems like this information has been in the DOM since 2018.

mifi commented 2 years ago

Ok i'll add a TODO for the DOM alternative fallback. at least the bot works again now

Brozzor commented 2 years ago

hi i have a little error from last fix : image

AureliusAce commented 2 years ago

Dang, it really works again now. Thanks man, U Guys are the best! Thank you for your Work mifi 💪

metapodcod commented 2 years ago

Basically we need to find a way to find the User ID of an account, only knowing the account's username. Previously we used methods like these: https://stackoverflow.com/questions/11796349/instagram-how-to-get-my-user-id-from-username but it seems that none of those work anymore.

can look into other bots like https://github.com/InstaPy/InstaPy how they do it

The user ID is needed for GraphQL queries.

@mifi https://github.com/InstaPy/InstaPy/issues/6615 we are having this problem, how can we solve it, can you help? https://github.com/InstaPy/InstaPy/blob/master/instapy/util.py#L2639

mifi commented 2 years ago

@metapodcod see discussion above and https://github.com/mifi/instauto/commit/b3a5d7c8ba3362513de8b3a1d863956b2114b363

metapodcod commented 2 years ago

@metapodcod see discussion above and mifi/instauto@b3a5d7c

I don't know how to make this change in python

denstream-io commented 2 years ago

@metapodcod I came here after reading your post on Stackoverflow, I think this is a different implementation in JavaScript with a somewhat different idea.

yudenichgabriel commented 2 years ago

Seems like it requires a few extra headers in order to allow the request to passthrough. If you are using Puppeteer you could specifically intercept this request and get it's response data. Another alternative is that, it seems like the user id gets loaded at some point into the DOM

What headers it needs? I have pass it the user-agent to the requests in python but its just the same "mismatch useragent". Can someone help me with this?