From 606644068c22de0bdb8bec8158cd4bc042b07add Mon Sep 17 00:00:00 2001 From: Romeo Phillips Date: Fri, 19 Apr 2024 10:45:05 -0700 Subject: [PATCH] remove identifying tokens --- src/meta_ai_api/__init__.py | 2 +- src/meta_ai_api/main.py | 18 +++++++++++++----- src/meta_ai_api/utils.py | 9 +++++---- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/meta_ai_api/__init__.py b/src/meta_ai_api/__init__.py index ebd5dbd..dba3056 100644 --- a/src/meta_ai_api/__init__.py +++ b/src/meta_ai_api/__init__.py @@ -1,2 +1,2 @@ -__version__ = "1.1.0" +__version__ = "1.1.1" from .main import MetaAI # noqa diff --git a/src/meta_ai_api/main.py b/src/meta_ai_api/main.py index a3e86a4..a0af02b 100644 --- a/src/meta_ai_api/main.py +++ b/src/meta_ai_api/main.py @@ -40,7 +40,7 @@ def get_access_token(self) -> str: url = "https://www.meta.ai/api/graphql/" payload = { - "lsd": "AVrWIDJrQQI", + "lsd": self.cookies["lsd"], "fb_api_caller_class": "RelayModern", "fb_api_req_friendly_name": "useAbraAcceptTOSForTempUserMutation", "variables": { @@ -56,7 +56,6 @@ def get_access_token(self) -> str: "cookie": f'_js_datr={self.cookies["_js_datr"]}; abra_csrf={self.cookies["abra_csrf"]}; datr={self.cookies["datr"]};', "sec-fetch-site": "same-origin", "x-fb-friendly-name": "useAbraAcceptTOSForTempUserMutation", - "x-fb-lsd": "AVrWIDJrQQI", } response = self.session.post(url, headers=headers, data=payload) @@ -151,9 +150,18 @@ def get_cookies(self) -> dict: session = HTMLSession() response = session.get("https://www.meta.ai/") return { - "_js_datr": extract_value(response.text, "_js_datr"), - "abra_csrf": extract_value(response.text, "abra_csrf"), - "datr": extract_value(response.text, "datr"), + "_js_datr": extract_value( + response.text, start_str='_js_datr":{"value":"', end_str='",' + ), + "abra_csrf": extract_value( + response.text, start_str='abra_csrf":{"value":"', end_str='",' + ), + "datr": extract_value( + response.text, start_str='datr":{"value":"', end_str='",' + ), + "lsd": extract_value( + response.text, start_str='"LSD",[],{"token":"', end_str='"}' + ), } def fetch_sources(self, fetch_id: str) -> List[Dict]: diff --git a/src/meta_ai_api/utils.py b/src/meta_ai_api/utils.py index 2f09666..42e6a37 100644 --- a/src/meta_ai_api/utils.py +++ b/src/meta_ai_api/utils.py @@ -34,19 +34,20 @@ def combine_and_mask(timestamp, random_value): return str(threading_id) -def extract_value(text: str, key: str) -> str: +def extract_value(text: str, start_str: str, end_str: str) -> str: """ Helper function to extract a specific value from the given text using a key. Args: text (str): The text from which to extract the value. - key (str): The key associated with the value. + start_str (str): The starting key. + end_str (str): The ending key. Returns: str: The extracted value. """ - start = text.find(f'{key}":{{"value":"') + len(f'{key}":{{"value":"') - end = text.find('",', start) + start = text.find(start_str) + len(start_str) + end = text.find(end_str, start) return text[start:end]