fbchat-v2 2.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fbchat_v2/__init__.py +30 -0
- fbchat_v2/_core/README.md +261 -0
- fbchat_v2/_core/README_EN.md +261 -0
- fbchat_v2/_core/__init__.py +1 -0
- fbchat_v2/_core/_facebookLogin.py +171 -0
- fbchat_v2/_core/_session.py +61 -0
- fbchat_v2/_core/_utils.py +135 -0
- fbchat_v2/_features/README.md +263 -0
- fbchat_v2/_features/README_EN.md +263 -0
- fbchat_v2/_features/__init__.py +1 -0
- fbchat_v2/_features/_facebook/__init__.py +9 -0
- fbchat_v2/_features/_facebook/_blocking.py +86 -0
- fbchat_v2/_features/_facebook/_changeBio.py +45 -0
- fbchat_v2/_features/_facebook/_createPost.py +90 -0
- fbchat_v2/_features/_facebook/_get_user_info.py +83 -0
- fbchat_v2/_features/_facebook/_marketplace.py +206 -0
- fbchat_v2/_features/_facebook/_notification.py +36 -0
- fbchat_v2/_features/_facebook/_professional.py +45 -0
- fbchat_v2/_features/_facebook/_registerOnProfile.py +47 -0
- fbchat_v2/_features/_facebook/_search.py +75 -0
- fbchat_v2/_features/_thread/__init__.py +6 -0
- fbchat_v2/_features/_thread/_addAdmin.py +22 -0
- fbchat_v2/_features/_thread/_all_thread_data.py +114 -0
- fbchat_v2/_features/_thread/_changeEmoji.py +18 -0
- fbchat_v2/_features/_thread/_changeNameThread.py +53 -0
- fbchat_v2/_features/_thread/_changeNickname.py +23 -0
- fbchat_v2/_messaging/README.md +412 -0
- fbchat_v2/_messaging/README_EN.md +412 -0
- fbchat_v2/_messaging/__init__.py +1 -0
- fbchat_v2/_messaging/_attachments.py +62 -0
- fbchat_v2/_messaging/_listening.py +222 -0
- fbchat_v2/_messaging/_listening_e2ee.py +475 -0
- fbchat_v2/_messaging/_message_requests.py +41 -0
- fbchat_v2/_messaging/_reactions.py +53 -0
- fbchat_v2/_messaging/_send.py +151 -0
- fbchat_v2/_messaging/_unsend.py +18 -0
- fbchat_v2/py.typed +1 -0
- fbchat_v2-2.1.0.dist-info/METADATA +770 -0
- fbchat_v2-2.1.0.dist-info/RECORD +41 -0
- fbchat_v2-2.1.0.dist-info/WHEEL +4 -0
- fbchat_v2-2.1.0.dist-info/licenses/LICENSE +201 -0
fbchat_v2/__init__.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""
|
|
2
|
+
fbchat-v2 — modern, account-based Python library for the unofficial Facebook
|
|
3
|
+
Messenger API (with E2EE support via Go bridge).
|
|
4
|
+
|
|
5
|
+
Public re-exports:
|
|
6
|
+
listeningEvent — group-message MQTT listener
|
|
7
|
+
listeningE2EEEvent — 1-on-1 E2EE listener (requires Go bridge binary)
|
|
8
|
+
dataGetHome — bootstrap dataFB session dict from cookies
|
|
9
|
+
|
|
10
|
+
Xem README để biết chi tiết.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
__version__ = "2.1.0"
|
|
16
|
+
__author__ = "MinhHuyDev"
|
|
17
|
+
__license__ = "MIT"
|
|
18
|
+
|
|
19
|
+
from ._core._session import dataGetHome
|
|
20
|
+
from ._messaging._listening import listeningEvent
|
|
21
|
+
from ._messaging._listening_e2ee import listeningE2EEEvent
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"__version__",
|
|
25
|
+
"__author__",
|
|
26
|
+
"__license__",
|
|
27
|
+
"dataGetHome",
|
|
28
|
+
"listeningEvent",
|
|
29
|
+
"listeningE2EEEvent",
|
|
30
|
+
]
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# `_core` — Tầng nền tảng
|
|
2
|
+
|
|
3
|
+
> Foundation layer của `fbchat-v2`. Khởi tạo phiên, sinh payload, parse cookie, sinh ID — mọi tầng phía trên đều phụ thuộc vào module này.
|
|
4
|
+
|
|
5
|
+
[](.)
|
|
6
|
+
[](.)
|
|
7
|
+
[](README_EN.md)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 📑 Mục lục
|
|
12
|
+
|
|
13
|
+
- [Vai trò](#-vai-trò)
|
|
14
|
+
- [Cấu trúc thư mục](#-cấu-trúc-thư-mục)
|
|
15
|
+
- [Public API](#-public-api)
|
|
16
|
+
- [Hợp đồng dữ liệu `dataFB`](#-hợp-đồng-dữ-liệu-datafb)
|
|
17
|
+
- [Tham chiếu module](#-tham-chiếu-module)
|
|
18
|
+
- [`_session.py`](#sessionpy)
|
|
19
|
+
- [`_utils.py`](#utilspy)
|
|
20
|
+
- [`_facebookLogin.py`](#facebookloginpy)
|
|
21
|
+
- [Sơ đồ phụ thuộc](#-sơ-đồ-phụ-thuộc)
|
|
22
|
+
- [Ví dụ](#-ví-dụ)
|
|
23
|
+
- [Khắc phục sự cố](#-khắc-phục-sự-cố)
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 🎯 Vai trò
|
|
28
|
+
|
|
29
|
+
`_core` là tầng kỹ thuật dùng chung — **không** chứa tính năng người dùng cuối. Trách nhiệm chính:
|
|
30
|
+
|
|
31
|
+
- 🔑 Khởi tạo **phiên làm việc** từ cookie người dùng.
|
|
32
|
+
- 🧱 Tạo **payload / request** chuẩn cho các endpoint Facebook.
|
|
33
|
+
- 🍪 Parse cookie & trích xuất **token động** (`fb_dtsg`, `jazoest`, …).
|
|
34
|
+
- 🆔 Sinh các loại **ID** phục vụ luồng gửi / nhận tin.
|
|
35
|
+
- 🛠 Cung cấp **utilities** dùng lại bởi `_features` và `_messaging`.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 📂 Cấu trúc thư mục
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
src/_core/
|
|
43
|
+
├── __init__.py
|
|
44
|
+
├── _session.py # Khởi tạo dataFB từ cookie
|
|
45
|
+
├── _utils.py # HTTP helpers, parser, ID generator…
|
|
46
|
+
├── _facebookLogin.py # Đăng nhập username/password (+ 2FA)
|
|
47
|
+
├── README.md # ← bạn đang ở đây
|
|
48
|
+
└── README_EN.md
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 📦 Public API
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
# src/_core/__init__.py
|
|
57
|
+
__all__ = ["_session", "_utils", "_facebookLogin"]
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Sau khi `import _core`, bạn có thể truy cập tất cả module con thông qua `_core._session`, `_core._utils`, `_core._facebookLogin`.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 🧩 Hợp đồng dữ liệu `dataFB`
|
|
65
|
+
|
|
66
|
+
`_session.dataGetHome(setCookies)` trả về một `dict` (thường đặt tên là **`dataFB`**) — đây là **single source of truth** cho mọi request về sau.
|
|
67
|
+
|
|
68
|
+
| Khoá | Mô tả |
|
|
69
|
+
|---|---|
|
|
70
|
+
| `fb_dtsg` | Token CSRF runtime |
|
|
71
|
+
| `fb_dtsg_ag` | Biến thể `fb_dtsg` cho một số endpoint |
|
|
72
|
+
| `jazoest` | Token kèm `fb_dtsg` |
|
|
73
|
+
| `hash` | Hash phiên hiện tại |
|
|
74
|
+
| `sessionID` | ID phiên runtime |
|
|
75
|
+
| `FacebookID` | UID người dùng đang đăng nhập |
|
|
76
|
+
| `clientRevision` | Revision client (cập nhật theo Facebook) |
|
|
77
|
+
| `cookieFacebook` | Cookie gốc dạng dict, sẵn sàng cho `requests` |
|
|
78
|
+
|
|
79
|
+
> ⚠️ Gần như **mọi** module trong `_features/*` và `_messaging/*` đều phụ thuộc vào các giá trị này.
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 📚 Tham chiếu module
|
|
84
|
+
|
|
85
|
+
### `_session.py`
|
|
86
|
+
|
|
87
|
+
#### `dataGetHome(setCookies: str) -> dict`
|
|
88
|
+
|
|
89
|
+
Truy cập `https://www.facebook.com/` bằng cookie đã cung cấp, trích xuất các token cần thiết.
|
|
90
|
+
|
|
91
|
+
| Tham số | Kiểu | Mô tả |
|
|
92
|
+
|---|---|---|
|
|
93
|
+
| `setCookies` | `str` | Cookie thô, ví dụ `"c_user=...; xs=...; fr=...; datr=...;"` |
|
|
94
|
+
|
|
95
|
+
**Trả về:** `dict` theo schema `dataFB` ở trên.
|
|
96
|
+
|
|
97
|
+
**Quy trình:**
|
|
98
|
+
|
|
99
|
+
1. Tạo header GET kiểu trình duyệt.
|
|
100
|
+
2. Chuyển cookie string → dict (`_utils.parse_cookie_string`).
|
|
101
|
+
3. Tải HTML homepage.
|
|
102
|
+
4. Cắt token bằng `_utils.dataSplit`.
|
|
103
|
+
5. Trả về session dict.
|
|
104
|
+
|
|
105
|
+
> ⚠️ Cách trích xuất hiện dùng split-marker; có thể vỡ khi Facebook đổi HTML. Tài khoản cũng có thể dính **checkpoint**.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
### `_utils.py`
|
|
110
|
+
|
|
111
|
+
Module quan trọng nhất của `_core`. Gồm 5 nhóm hàm chính:
|
|
112
|
+
|
|
113
|
+
#### A. HTTP / Request
|
|
114
|
+
|
|
115
|
+
| Hàm | Mô tả |
|
|
116
|
+
|---|---|
|
|
117
|
+
| `Headers(dataForm=None, Host=None)` | Tạo bộ header chuẩn; tự thêm `Content-Length` nếu có `dataForm`. |
|
|
118
|
+
| `parse_cookie_string(cookie_string)` | Cookie string → `dict` cho `requests`. |
|
|
119
|
+
| `mainRequests(urlRequests, dataForm, setCookies)` | Trả về `kwargs` sẵn sàng dùng `requests.post(**kwargs)`. |
|
|
120
|
+
|
|
121
|
+
#### B. Parse / Format
|
|
122
|
+
|
|
123
|
+
| Hàm | Mô tả |
|
|
124
|
+
|---|---|
|
|
125
|
+
| `digitToChar(digit)` | Chuyển digit → char. |
|
|
126
|
+
| `str_base(number, base)` | Đổi cơ số. |
|
|
127
|
+
| `dataSplit(...)` | Cắt chuỗi theo delimiter. |
|
|
128
|
+
| `clearHTML(text)` | Loại thẻ HTML qua regex. |
|
|
129
|
+
| `formatResults(type, text)` | Chuẩn hoá output `{ "status": ..., "message": ... }`. |
|
|
130
|
+
|
|
131
|
+
#### C. Form builder tổng quát
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
formAll(dataFB, FBApiReqFriendlyName=None, docID=None, requireGraphql=None)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Backbone của hầu hết flow request, hỗ trợ 2 chế độ:
|
|
138
|
+
|
|
139
|
+
1. **GraphQL** (`requireGraphql is None`): có `fb_api_req_friendly_name`, `doc_id`, `fb_api_caller_class`, …
|
|
140
|
+
2. **Legacy / minimal** (`requireGraphql != None`): chỉ giữ trường tối thiểu.
|
|
141
|
+
|
|
142
|
+
#### D. Messaging ID generators
|
|
143
|
+
|
|
144
|
+
`generate_session_id()` · `generate_client_id()` · `gen_threading_id()` · `json_minimal(data)` · `_set_chat_on(value)`
|
|
145
|
+
|
|
146
|
+
> Dùng nhiều trong `_messaging._send` và `_messaging._listening`.
|
|
147
|
+
|
|
148
|
+
#### E. Tiện ích khác
|
|
149
|
+
|
|
150
|
+
`require_list(list_)` · `get_files_from_paths(filenames)` · `randStr(length)`
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
### `_facebookLogin.py`
|
|
155
|
+
|
|
156
|
+
Đăng nhập Facebook bằng **username / password** (+ tuỳ chọn 2FA).
|
|
157
|
+
|
|
158
|
+
#### Thành phần công khai
|
|
159
|
+
|
|
160
|
+
| Symbol | Mô tả |
|
|
161
|
+
|---|---|
|
|
162
|
+
| `class loginFacebook(username, password, AuthenticationGoogleCode=None)` | Đăng nhập; gọi `.main()` để chạy. |
|
|
163
|
+
| `GetToken2FA(key2Fa)` | Lấy OTP 2FA qua `https://2fa.live/tok/...`. |
|
|
164
|
+
| `jsonResults(...)` | Chuẩn hoá cấu trúc trả về. |
|
|
165
|
+
|
|
166
|
+
#### Kết quả
|
|
167
|
+
|
|
168
|
+
| Trạng thái | Trường trả về |
|
|
169
|
+
|---|---|
|
|
170
|
+
| ✅ Thành công | `success.setCookies` · `success.accessTokenFB` · `success.cookiesKey-ValueList` |
|
|
171
|
+
| ❌ Thất bại | `error.title` · `error.description` · `error.error_subcode` · `error.error_code` · `error.fbtrace_id` |
|
|
172
|
+
|
|
173
|
+
> 🔒 Module xử lý dữ liệu cực kỳ nhạy cảm. **Khuyến nghị mạnh mẽ** dùng cookie-login trong production.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## 🔗 Sơ đồ phụ thuộc
|
|
178
|
+
|
|
179
|
+
`_core._utils` được import rộng rãi bởi:
|
|
180
|
+
|
|
181
|
+
- `src/_features/_facebook/*`
|
|
182
|
+
- `src/_features/_thread/*`
|
|
183
|
+
- `src/_messaging/*`
|
|
184
|
+
|
|
185
|
+
Helpers được dùng nhiều nhất:
|
|
186
|
+
|
|
187
|
+
```text
|
|
188
|
+
formAll · mainRequests · parse_cookie_string · Headers · formatResults
|
|
189
|
+
gen_threading_id · generate_session_id · generate_client_id
|
|
190
|
+
str_base · randStr · get_files_from_paths
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
> ⚠️ **Cảnh báo:** thay đổi logic core payload / cookie sẽ ảnh hưởng dây chuyền tới phần lớn tính năng.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## 💡 Ví dụ
|
|
198
|
+
|
|
199
|
+
### Khởi tạo `dataFB` từ cookie
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
from _core._session import dataGetHome
|
|
203
|
+
|
|
204
|
+
setCookies = "c_user=...; xs=...; fr=...; datr=...;"
|
|
205
|
+
dataFB = dataGetHome(setCookies)
|
|
206
|
+
|
|
207
|
+
print(dataFB["FacebookID"])
|
|
208
|
+
print(dataFB["fb_dtsg"])
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Gửi request GraphQL
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
import json, requests
|
|
215
|
+
from _core._utils import formAll, mainRequests
|
|
216
|
+
|
|
217
|
+
dataForm = formAll(
|
|
218
|
+
dataFB,
|
|
219
|
+
FBApiReqFriendlyName="CometNotificationsDropdownQuery",
|
|
220
|
+
docID=6770067089747450,
|
|
221
|
+
)
|
|
222
|
+
dataForm["variables"] = json.dumps({
|
|
223
|
+
"count": 10,
|
|
224
|
+
"environment": "MAIN_SURFACE",
|
|
225
|
+
"scale": 1,
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
resp = requests.post(**mainRequests(
|
|
229
|
+
"https://www.facebook.com/api/graphql/",
|
|
230
|
+
dataForm,
|
|
231
|
+
dataFB["cookieFacebook"],
|
|
232
|
+
))
|
|
233
|
+
print(resp.status_code)
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Payload tối giản (non-GraphQL)
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
from _core._utils import formAll
|
|
240
|
+
|
|
241
|
+
payload = formAll(dataFB, requireGraphql=False)
|
|
242
|
+
payload["message_id"] = "mid...."
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## 🛠 Khắc phục sự cố
|
|
248
|
+
|
|
249
|
+
| Triệu chứng | Hướng xử lý |
|
|
250
|
+
|---|---|
|
|
251
|
+
| Nhiều request lỗi auth/session | Cookie hết hạn → tạo lại `dataFB` qua `dataGetHome(...)`. |
|
|
252
|
+
| Trường trả về giá trị fallback | HTML homepage đã đổi → cập nhật split markers trong `_session.py`. |
|
|
253
|
+
| Login dính checkpoint | Đổi sang cookie-login; nếu giữ nguyên login flow, kiểm tra IP / 2FA. |
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
<div align="right">
|
|
258
|
+
|
|
259
|
+
⬆️ [Về README chính](../../README.md) · 🇬🇧 [English](README_EN.md)
|
|
260
|
+
|
|
261
|
+
</div>
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# `_core` — Foundation Layer
|
|
2
|
+
|
|
3
|
+
> The foundation of `fbchat-v2`. Bootstraps sessions, builds request payloads, parses cookies, generates IDs — every higher layer depends on this module.
|
|
4
|
+
|
|
5
|
+
[](.)
|
|
6
|
+
[](.)
|
|
7
|
+
[](README.md)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 📑 Table of Contents
|
|
12
|
+
|
|
13
|
+
- [Responsibilities](#-responsibilities)
|
|
14
|
+
- [Folder Structure](#-folder-structure)
|
|
15
|
+
- [Public API](#-public-api)
|
|
16
|
+
- [The `dataFB` Contract](#-the-datafb-contract)
|
|
17
|
+
- [Module Reference](#-module-reference)
|
|
18
|
+
- [`_session.py`](#sessionpy)
|
|
19
|
+
- [`_utils.py`](#utilspy)
|
|
20
|
+
- [`_facebookLogin.py`](#facebookloginpy)
|
|
21
|
+
- [Dependency Map](#-dependency-map)
|
|
22
|
+
- [Examples](#-examples)
|
|
23
|
+
- [Troubleshooting](#-troubleshooting)
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 🎯 Responsibilities
|
|
28
|
+
|
|
29
|
+
`_core` is the shared technical foundation — it does **not** implement end-user features. Its responsibilities are:
|
|
30
|
+
|
|
31
|
+
- 🔑 Bootstrap a **user session** from cookies.
|
|
32
|
+
- 🧱 Build standardized **payloads / requests** for Facebook endpoints.
|
|
33
|
+
- 🍪 Parse cookies and extract **dynamic tokens** (`fb_dtsg`, `jazoest`, …).
|
|
34
|
+
- 🆔 Generate the various **IDs** required by send/listen flows.
|
|
35
|
+
- 🛠 Provide **utilities** reused by `_features` and `_messaging`.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 📂 Folder Structure
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
src/_core/
|
|
43
|
+
├── __init__.py
|
|
44
|
+
├── _session.py # Bootstraps dataFB from cookies
|
|
45
|
+
├── _utils.py # HTTP helpers, parsers, ID generators…
|
|
46
|
+
├── _facebookLogin.py # Username/password login (+ 2FA)
|
|
47
|
+
├── README.md
|
|
48
|
+
└── README_EN.md # ← you are here
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 📦 Public API
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
# src/_core/__init__.py
|
|
57
|
+
__all__ = ["_session", "_utils", "_facebookLogin"]
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
After `import _core` you can reach every submodule via `_core._session`, `_core._utils`, `_core._facebookLogin`.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 🧩 The `dataFB` Contract
|
|
65
|
+
|
|
66
|
+
`_session.dataGetHome(setCookies)` returns a `dict` (commonly named **`dataFB`**) — the **single source of truth** for every subsequent request.
|
|
67
|
+
|
|
68
|
+
| Key | Description |
|
|
69
|
+
|---|---|
|
|
70
|
+
| `fb_dtsg` | Runtime CSRF token |
|
|
71
|
+
| `fb_dtsg_ag` | Variant of `fb_dtsg` for certain endpoints |
|
|
72
|
+
| `jazoest` | Companion token to `fb_dtsg` |
|
|
73
|
+
| `hash` | Current session hash |
|
|
74
|
+
| `sessionID` | Runtime session ID |
|
|
75
|
+
| `FacebookID` | UID of the logged-in account |
|
|
76
|
+
| `clientRevision` | Client revision (Facebook updates it) |
|
|
77
|
+
| `cookieFacebook` | Original cookies as a dict, ready for `requests` |
|
|
78
|
+
|
|
79
|
+
> ⚠️ Almost **every** module in `_features/*` and `_messaging/*` depends on these values.
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 📚 Module Reference
|
|
84
|
+
|
|
85
|
+
### `_session.py`
|
|
86
|
+
|
|
87
|
+
#### `dataGetHome(setCookies: str) -> dict`
|
|
88
|
+
|
|
89
|
+
Hits `https://www.facebook.com/` with the supplied cookies and extracts the tokens needed for follow-up API calls.
|
|
90
|
+
|
|
91
|
+
| Param | Type | Description |
|
|
92
|
+
|---|---|---|
|
|
93
|
+
| `setCookies` | `str` | Raw cookie string, e.g. `"c_user=...; xs=...; fr=...; datr=...;"` |
|
|
94
|
+
|
|
95
|
+
**Returns:** a `dict` matching the `dataFB` schema above.
|
|
96
|
+
|
|
97
|
+
**Workflow:**
|
|
98
|
+
|
|
99
|
+
1. Build browser-like GET headers.
|
|
100
|
+
2. Convert the cookie string into a dict (`_utils.parse_cookie_string`).
|
|
101
|
+
3. Download the homepage HTML.
|
|
102
|
+
4. Extract tokens via `_utils.dataSplit`.
|
|
103
|
+
5. Return the session dict.
|
|
104
|
+
|
|
105
|
+
> ⚠️ Extraction is split-marker based and may break when Facebook changes its HTML. Accounts can also hit **checkpoint** flows.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
### `_utils.py`
|
|
110
|
+
|
|
111
|
+
The most important module inside `_core`. Five helper groups:
|
|
112
|
+
|
|
113
|
+
#### A. HTTP / Request
|
|
114
|
+
|
|
115
|
+
| Function | Description |
|
|
116
|
+
|---|---|
|
|
117
|
+
| `Headers(dataForm=None, Host=None)` | Builds the base headers; auto-sets `Content-Length` when `dataForm` is given. |
|
|
118
|
+
| `parse_cookie_string(cookie_string)` | Cookie string → `dict` for `requests`. |
|
|
119
|
+
| `mainRequests(urlRequests, dataForm, setCookies)` | Returns a `kwargs` dict ready for `requests.post(**kwargs)`. |
|
|
120
|
+
|
|
121
|
+
#### B. Parse / Format
|
|
122
|
+
|
|
123
|
+
| Function | Description |
|
|
124
|
+
|---|---|
|
|
125
|
+
| `digitToChar(digit)` | Digit → char mapping. |
|
|
126
|
+
| `str_base(number, base)` | Numeric base conversion. |
|
|
127
|
+
| `dataSplit(...)` | Slice text by delimiter. |
|
|
128
|
+
| `clearHTML(text)` | Strip HTML tags via regex. |
|
|
129
|
+
| `formatResults(type, text)` | Normalize output to `{ "status": ..., "message": ... }`. |
|
|
130
|
+
|
|
131
|
+
#### C. General Form Builder
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
formAll(dataFB, FBApiReqFriendlyName=None, docID=None, requireGraphql=None)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
The backbone of most request flows — supports two modes:
|
|
138
|
+
|
|
139
|
+
1. **GraphQL** (`requireGraphql is None`): includes `fb_api_req_friendly_name`, `doc_id`, `fb_api_caller_class`, …
|
|
140
|
+
2. **Legacy / minimal** (`requireGraphql != None`): keeps only the fields needed for non-GraphQL endpoints.
|
|
141
|
+
|
|
142
|
+
#### D. Messaging ID Generators
|
|
143
|
+
|
|
144
|
+
`generate_session_id()` · `generate_client_id()` · `gen_threading_id()` · `json_minimal(data)` · `_set_chat_on(value)`
|
|
145
|
+
|
|
146
|
+
> Used heavily by `_messaging._send` and `_messaging._listening`.
|
|
147
|
+
|
|
148
|
+
#### E. Misc Utilities
|
|
149
|
+
|
|
150
|
+
`require_list(list_)` · `get_files_from_paths(filenames)` · `randStr(length)`
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
### `_facebookLogin.py`
|
|
155
|
+
|
|
156
|
+
Logs into Facebook with **username / password** (+ optional 2FA).
|
|
157
|
+
|
|
158
|
+
#### Public components
|
|
159
|
+
|
|
160
|
+
| Symbol | Description |
|
|
161
|
+
|---|---|
|
|
162
|
+
| `class loginFacebook(username, password, AuthenticationGoogleCode=None)` | Login class; call `.main()` to execute. |
|
|
163
|
+
| `GetToken2FA(key2Fa)` | Fetches a 2FA OTP via `https://2fa.live/tok/...`. |
|
|
164
|
+
| `jsonResults(...)` | Normalizes the response shape. |
|
|
165
|
+
|
|
166
|
+
#### Result shape
|
|
167
|
+
|
|
168
|
+
| Status | Returned fields |
|
|
169
|
+
|---|---|
|
|
170
|
+
| ✅ Success | `success.setCookies` · `success.accessTokenFB` · `success.cookiesKey-ValueList` |
|
|
171
|
+
| ❌ Failure | `error.title` · `error.description` · `error.error_subcode` · `error.error_code` · `error.fbtrace_id` |
|
|
172
|
+
|
|
173
|
+
> 🔒 This module handles highly sensitive data. **Strongly prefer** cookie-based login in production.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## 🔗 Dependency Map
|
|
178
|
+
|
|
179
|
+
`_core._utils` is widely imported by:
|
|
180
|
+
|
|
181
|
+
- `src/_features/_facebook/*`
|
|
182
|
+
- `src/_features/_thread/*`
|
|
183
|
+
- `src/_messaging/*`
|
|
184
|
+
|
|
185
|
+
Most-used helpers:
|
|
186
|
+
|
|
187
|
+
```text
|
|
188
|
+
formAll · mainRequests · parse_cookie_string · Headers · formatResults
|
|
189
|
+
gen_threading_id · generate_session_id · generate_client_id
|
|
190
|
+
str_base · randStr · get_files_from_paths
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
> ⚠️ **Warning:** changes to core payload / cookie logic ripple across most features.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## 💡 Examples
|
|
198
|
+
|
|
199
|
+
### Bootstrap `dataFB` from cookies
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
from _core._session import dataGetHome
|
|
203
|
+
|
|
204
|
+
setCookies = "c_user=...; xs=...; fr=...; datr=...;"
|
|
205
|
+
dataFB = dataGetHome(setCookies)
|
|
206
|
+
|
|
207
|
+
print(dataFB["FacebookID"])
|
|
208
|
+
print(dataFB["fb_dtsg"])
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Build & send a GraphQL request
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
import json, requests
|
|
215
|
+
from _core._utils import formAll, mainRequests
|
|
216
|
+
|
|
217
|
+
dataForm = formAll(
|
|
218
|
+
dataFB,
|
|
219
|
+
FBApiReqFriendlyName="CometNotificationsDropdownQuery",
|
|
220
|
+
docID=6770067089747450,
|
|
221
|
+
)
|
|
222
|
+
dataForm["variables"] = json.dumps({
|
|
223
|
+
"count": 10,
|
|
224
|
+
"environment": "MAIN_SURFACE",
|
|
225
|
+
"scale": 1,
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
resp = requests.post(**mainRequests(
|
|
229
|
+
"https://www.facebook.com/api/graphql/",
|
|
230
|
+
dataForm,
|
|
231
|
+
dataFB["cookieFacebook"],
|
|
232
|
+
))
|
|
233
|
+
print(resp.status_code)
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Minimal payload (non-GraphQL)
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
from _core._utils import formAll
|
|
240
|
+
|
|
241
|
+
payload = formAll(dataFB, requireGraphql=False)
|
|
242
|
+
payload["message_id"] = "mid...."
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## 🛠 Troubleshooting
|
|
248
|
+
|
|
249
|
+
| Symptom | Suggested fix |
|
|
250
|
+
|---|---|
|
|
251
|
+
| Many requests fail with auth/session errors | Cookies expired → regenerate `dataFB` via `dataGetHome(...)`. |
|
|
252
|
+
| Parsed field returns a fallback value | Homepage HTML changed → update split markers in `_session.py`. |
|
|
253
|
+
| Login hits checkpoint | Switch to cookie-based login; if you must keep the login flow, check IP / 2FA. |
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
<div align="right">
|
|
258
|
+
|
|
259
|
+
⬆️ [Back to main README](../../README_EN.md) · 🇻🇳 [Tiếng Việt](README.md)
|
|
260
|
+
|
|
261
|
+
</div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__all__ = ["_session", "_utils", "_facebookLogin"]
|