-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
93 lines (79 loc) · 2.87 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from flask import Flask, request, jsonify
import requests
import json
app = Flask(__name__)
# Route 1: Fetch userid by username
@app.route("/userid/<username>", methods=["GET"])
def get_userid(username):
try:
url = "https://www.threads.net/ajax/bulk-route-definitions/"
headers = {
"accept": "*/*",
"accept-language": "en-US,en;q=0.9",
"content-type": "application/x-www-form-urlencoded",
"sec-fetch-site": "same-origin",
"x-fb-lsd": "4GaYIJW6lxs-XRVfHawU8K",
}
data = {
"route_urls[0]": "/@" + username,
"__user": "0",
"__a": "1",
"__comet_req": "29",
"lsd": "4GaYIJW6lxs-XRVfHawU8K",
}
response = requests.post(url, headers=headers, data=data)
result = response.text.replace("for (;;);", "")
result = json.loads(result)
userid = result["payload"]["payloads"]["/@" +
username]["result"]["exports"]["rootView"]["props"]["user_id"]
return jsonify({"userid": userid})
except Exception as e:
print("error", e)
return jsonify({"error": "Internal Server Error"}), 500
# Route 2: Fetch user profile by userid
@app.route("/userprofile/<userid>", methods=["GET"])
def get_user_profile(userid):
try:
url = "https://www.threads.net/api/graphql"
headers = {
"x-fb-lsd": "BMckKFfB3JDIA2XkhD8-ez",
"x-ig-app-id": "238260118697367",
"Content-Type": "application/x-www-form-urlencoded",
}
data = {
"lsd": "BMckKFfB3JDIA2XkhD8-ez",
"variables": json.dumps({"userID": userid}),
"doc_id": "23996318473300828",
}
response = requests.post(url, headers=headers, data=data)
result = response.json()
return jsonify(result)
except Exception as e:
print("error", e)
return jsonify({"error": "Internal Server Error"}), 500
# Route 3: Fetch threads or posts of userid
@app.route("/threads/<userid>", methods=["GET"])
def get_threads(userid):
try:
url = "https://www.threads.net/api/graphql"
headers = {
"x-fb-lsd": "A2LiqVjcY0jBE_DEsTaKNI",
"x-ig-app-id": "238260118697367",
"Content-Type": "application/x-www-form-urlencoded",
}
data = {
"dpr": "1",
"lsd": "A2LiqVjcY0jBE_DEsTaKNI",
"variables": json.dumps({"userID": userid}),
"doc_id": "6451898791498605",
}
response = requests.post(url, headers=headers, data=data)
result = response.json()
return jsonify(result)
except Exception as e:
print("error", e)
return jsonify({"error": "Internal Server Error"}), 500
# Start the server
if __name__ == "__main__":
port = 3000
app.run(port=port)