forked from iSarabjitDhiman/XClientTransaction
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart.py
More file actions
31 lines (24 loc) · 1.1 KB
/
quickstart.py
File metadata and controls
31 lines (24 loc) · 1.1 KB
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
import requests
from urllib.parse import urlparse
from x_client_transaction.utils import generate_headers, handle_x_migration
from x_client_transaction import ClientTransaction
session = requests.Session()
session.headers = generate_headers()
response = handle_x_migration(session)
# Example 1
# replace the url and http method as per your use case
url = "https://x.com/i/api/1.1/jot/client_event.json"
method = "POST"
path = urlparse(url=url).path
# path will be /i/api/1.1/jot/client_event.json in this case
# Example 2
user_by_screen_name_url = "https://x.com/i/api/graphql/1VOOyvKkiI3FMmkeDNxM9A/UserByScreenName"
user_by_screen_name_http_method = "GET"
user_by_screen_name_path = urlparse(url=url).path
# path will be /i/api/graphql/1VOOyvKkiI3FMmkeDNxM9A/UserByScreenName in this case
ct = ClientTransaction(response)
transaction_id = ct.generate_transaction_id(method=method, path=path)
transaction_id_for_user_by_screen_name_endpoint = ct.generate_transaction_id(
method=user_by_screen_name_http_method, path=user_by_screen_name_path)
print(transaction_id)
print(transaction_id_for_user_by_screen_name_endpoint)