Danie1 / threads-api

Unofficial Python API for Meta's Threads App
https://pypi.org/project/threads-api/
MIT License
121 stars 16 forks source link

Login Issues #16

Closed jet082 closed 1 year ago

jet082 commented 1 year ago

I went ahead and looked at the data being returned by Threads. I'm getting the following JSON with a known good username/password. I replaced anything that looks like sensitive data and presented the json in pretty printed format (removing the escapes as well).

{
  "layout": {
    "bloks_payload": {
      "data": [],
      "props": [
        {
          "id": "<KEPT SECRET>",
          "name": "ttrc_instance_id"
        },
        {
          "id": "<KEPT SECRET>",
          "name": "override_login_success_action"
        }
      ],
      "error_attribution": {
        "logging_id": "{\"callsite\":\"{\\\"product\\\":\\\"bloks_caa_login\\\",\\\"feature\\\":\\\"com.bloks.www.bloks.caa.login.async.send_login_request\\\",\\\"integration\\\":\\\"bloks_screen\\\",\\\"oncall\\\":\\\"caa_login\\\"}\",\"push_phase\":\"C3e\",\"version\":1,\"request_id\":\"<KEPT SECRET>\"}"
      },
      "tree": {
        "㐟": {
          "#": " (bk.action.core.TakeLast,
             (ig.action.cdsdialog.OpenDialog,
             (bk.action.tree.Make,
             (bk.action.i32.Const,
             13799),
             (bk.action.i32.Const,
             40),
             "Unable to log in",
             (bk.action.i32.Const,
             35),
             "An unexpected error occurred. Please try logging in again.",
             (bk.action.i32.Const,
             36),
             (bk.action.tree.Make,
             (bk.action.i32.Const,
             13800),
             (bk.action.i32.Const,
             36),
             "OK",
             (bk.action.i32.Const,
             35),
             (bk.action.core.FuncConst,
             (bk.action.logging.LogEvent,
             "caa_login_client_events_ig",
             "",
             (bk.action.map.Make,
             (bk.action.array.Make,
             "core",
             "login_params"),
             (bk.action.array.Make,
             (bk.action.map.Make,
             (bk.action.array.Make,
             "event",
             "event_category",
             "event_flow",
             "event_request_id",
             "event_step",
             "is_dark_mode",
             "exception_code",
             "exception_message",
             "exception_type",
             "extra_client_data",
             "logged_out_identifier",
             "logged_in_identifier",
             "waterfall_id"),
             (bk.action.array.Make,
             "login_error_dialog_ok_clicked",
             "login_home_page_interaction",
             "login_manual",
             "<KEPT SECRET>",
             "home_page",
             (ig.action.IsDarkModeEnabled),
             (bk.action.i32.Const,
             0),
             "",
             "",
             (bk.action.map.Make,
             (bk.action.array.Make),
             (bk.action.array.Make)),
             "",
             "",
             "<KEPT SECRET>")),
             (bk.action.map.Make,
             (bk.action.array.Make),
             (bk.action.array.Make))))))),
             (bk.action.i32.Const,
             42),
             (bk.action.i32.Const,
             0)),
             (bk.action.tree.Make,
             (bk.action.i32.Const,
             13808))),
             (bk.action.map.Make,
             (bk.action.array.Make,
             "should_dismiss_loading"),
             (bk.action.array.Make,
             (bk.action.bool.Const,
             true))))"
        }
      }
    }
  },
  "status": "ok"
}

The error given by the module is:

Exception: Error with the login response

The code generating this is simply:

from threads_api.src.threads_api import ThreadsAPI
import asyncio, os

myUsername = 'myUsername'
myPassword = 'myPassword'

async def post():
    api = ThreadsAPI()
    await api.login(myUsername, myPassword, cached_token_path=".token")
    result = await api.post("testing")

    if result:
        print("Post has been successfully posted")
    else:
        print("Unable to post.")

async def main():
    await post()

# Create an event loop and run the main function
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
MsLolita commented 1 year ago

threads' devs changed api, wait for author fix

Danie1 commented 1 year ago

First of all, thank you for taking interest in threads-api :)

It seems the login API indeed had changed a little (as can be seen in other APIs eg. for NPM) Having said that, my locally saved token in the cache is still working (feature added to our threads-api yesterday).

I will be monitoring and researching solutions for this. Thanks for notifying.

francistogram commented 1 year ago

@Danie1 seems like the password is now encrypted looks like the logic is supposed to be similar to the one on instagram-private-api so maybe this helps

https://github.com/junhoyeo/threads-api/issues/118#issuecomment-1632503110

Danie1 commented 1 year ago

Hey, please try v1.1.3. I changed the login logic to useinstagrapi which seems to work for generating tokens.

I believe it will also fix this as well https://github.com/dmytrostriletskyi/threads-net/issues/46

I will close this issue to mark as complete. Please open a new issue if the problem / a new one persists from v1.1.3+.