Skip to content

Commit

Permalink
remove identifying tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Strvm committed Apr 19, 2024
1 parent fdaca07 commit 6066440
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/meta_ai_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "1.1.0"
__version__ = "1.1.1"
from .main import MetaAI # noqa
18 changes: 13 additions & 5 deletions src/meta_ai_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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)
Expand Down Expand Up @@ -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]:
Expand Down
9 changes: 5 additions & 4 deletions src/meta_ai_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand Down

0 comments on commit 6066440

Please sign in to comment.