junhoyeo / threads-api

Unofficial, Reverse-Engineered Node.js/TypeScript client for Meta's Threads. Web UI Included.
https://threads.junho.io
MIT License
1.58k stars 134 forks source link

`getUserProfileLoggedIn` raises `ThreadsAPIError` with `"Oops, an error occurred.\n"` (from v1.6.0) #278

Open junhoyeo opened 11 months ago

junhoyeo commented 11 months ago

Could be temporary error in Instagram. Threads Join Count in #164 is not showing on my phone's IG app either.

describeIf(!!credentials)('getUserProfile (with auth)', () => {
  const threadsAPI = new ThreadsAPI({
    verbose: true,
    ...credentials,
  });

  it('Instagram # number to join Threads (#164)', async () => {
    // given
    const userID = await threadsAPI.getUserIDfromUsername('zuck');

    // when
    const user = await threadsAPI.getUserProfileLoggedIn(userID!);
    console.log(JSON.stringify(user));
  });
});
mrging1999 commented 9 months ago

@junhoyeo

I have been debugging this all day, and found out why the "Ooops" message returns what it does. it's a very very simple fix.

await _fetchAuthGetRequest(`\`${BASE_API_URL}/api/v1/users/${userID}/info?is_prefetch=false&entry_point=profile&from_module=ProfileViewModel`, theToken, options);

this line here, you simple need to change to:

await _fetchAuthGetRequest(`${BASE_API_URL}/api/v1/users/${userID}/info/?is_prefetch=false&entry_point=profile&from_module=ProfileViewModel`, theToken, options);

Notice the tiny change to /info/? from /info?

replace it with this additional slash and it will get rid of oops issue

mrging1999 commented 9 months ago

The issue now, is also that the api to lookup deep user infos doesn't use Authorization header... it uses cookies. The following cookies are required and MUST be logged in via a instagram session before running this (if you would like to get the full datas and not just the small data that doesn't require login).

In your code, you're adding the Authorization Bearer token, when this doesn't take it: https://i.instagram.com/api/v1/users/${userID}/info/?is_prefetch=false&entry_point=profile&from_module=ProfileViewModel

The required cookies to get past this for full infos is:

"mid=ZPm5QwALAAEBDgJAHRop6B5v-5HT; ig_did=85E55F14-7301-45B9-8692-368CA2F2BC57; csrftoken=1RDWL5Ow647RpWJjSkhinkEEE9VDIPGs; ds_user_id=19075201840; sessionid=19075201840%3AUq1yHAKBwloBmI%3A12%3AAYcUiKihLHDatWG2NTKdxeYm0a_ZEObc_v5IbXwB8g; shbid=\"8408\\05419075201840\\0541725623536:01f7e0634b84c148f56f19f0728beb92ae68fd777f14479368d933ec6fcd92d0ff68e6ee\"; shbts=\"1694087536\\05419075201840\\0541725623536:01f7c91ce42ac65751064025c8620a6a08c1110bcf1c8689b8d609ef0b67f1636d757084\"; datr=QLr5ZBt_LsNr3340s8J749qK; rur=\"LDC\\05419075201840\\0541725623931:01f7acfe112823f9d961e80b87459274715bc2f1994ba0cc744a118484a36b265f8a0143\""

Like i said before, these cookies should work for anyone (only if you want to get basic infos) but if you want full infos, you must login to instagram, return the cookies and import into this api endpoint within an active timeframe.

mrging1999 commented 9 months ago

The issue now, is also that the api to lookup deep user infos doesn't use Authorization header... it uses cookies. The following cookies are required and MUST be logged in via a instagram session before running this (if you would like to get the full datas and not just the small data that doesn't require login).

In your code, you're adding the Authorization Bearer token, when this doesn't take it: https://i.instagram.com/api/v1/users/${userID}/info/?is_prefetch=false&entry_point=profile&from_module=ProfileViewModel

The required cookies to get past this for full infos is:

"mid=ZPm5QwALAAEBDgJAHRop6B5v-5HT; ig_did=85E55F14-7301-45B9-8692-368CA2F2BC57; csrftoken=1RDWL5Ow647RpWJjSkhinkEEE9VDIPGs; ds_user_id=19075201840; sessionid=19075201840%3AUq1yHAKBwloBmI%3A12%3AAYcUiKihLHDatWG2NTKdxeYm0a_ZEObc_v5IbXwB8g; shbid=\"8408\\05419075201840\\0541725623536:01f7e0634b84c148f56f19f0728beb92ae68fd777f14479368d933ec6fcd92d0ff68e6ee\"; shbts=\"1694087536\\05419075201840\\0541725623536:01f7c91ce42ac65751064025c8620a6a08c1110bcf1c8689b8d609ef0b67f1636d757084\"; datr=QLr5ZBt_LsNr3340s8J749qK; rur=\"LDC\\05419075201840\\0541725623931:01f7acfe112823f9d961e80b87459274715bc2f1994ba0cc744a118484a36b265f8a0143\""

Like i said before, these cookies should work for anyone (only if you want to get basic infos) but if you want full infos, you must login to instagram, return the cookies and import into this api endpoint within an active timeframe.

After testing some values and variables, i just found out that only the sessionid cookie is needed. you can use any valid sessionid cookie inside this request endpoint and you'll be able to get full user infos... ;)