Twitter X-Client-Transaction-Id generator written in python.
Project description
X-Client-Transaction-ID
Twitter X-Client-Transaction-Id generator written in python.
Reference :
- Twitter Header: Part 1, Deobfuscation
- Twitter Header: Part 2, Reverse Engineering
- Twitter Header: Part 3, Generating the header
Installation
Install XClientTransaction with pip
pip install fork-xclienttransaction
Usage/Examples
python quickstart.py
Get x.com Home Page and ondemand.s File Response
Synchronous Version
import bs4
import requests
from x_client_transaction.utils import generate_headers, handle_x_migration, get_ondemand_file_url
# INITIALIZE SESSION
session = requests.Session()
session.headers = generate_headers()
# GET HOME PAGE RESPONSE
# required only when hitting twitter.com but not x.com
# returns bs4.BeautifulSoup object
home_page_response = handle_x_migration(session=session)
# for x.com no migration is required, just simply do
home_page = session.get(url="https://x.com")
home_page_response = bs4.BeautifulSoup(home_page.content, 'html.parser')
# GET ondemand.s FILE RESPONSE
ondemand_file_url = get_ondemand_file_url(response=home_page_response)
ondemand_file = session.get(url=ondemand_file_url)
ondemand_file_response = bs4.BeautifulSoup(ondemand_file.content, 'html.parser')
# Getting "Couldn't get KEY_BYTE indices" error? Try passing the original response or the response text
# both should work
# ondemand_file_response = ondemand_file
ondemand_file_response = ondemand_file.text
Async Version
import bs4
import httpx
from x_client_transaction.utils import generate_headers, handle_x_migration_async, get_ondemand_file_url
# INITIALIZE SESSION
session = httpx.AsyncClient(headers=generate_headers())
# GET HOME PAGE RESPONSE
# required only when hitting twitter.com but not x.com
# returns bs4.BeautifulSoup object
home_page_response = await handle_x_migration_async(session=session)
# for x.com no migration is required, just simply do
home_page = await session.get(url="https://x.com")
home_page_response = bs4.BeautifulSoup(home_page.content, 'html.parser')
# GET ondemand.s FILE RESPONSE
ondemand_file_url = get_ondemand_file_url(response=home_page_response)
ondemand_file = await session.get(url=ondemand_file_url)
ondemand_file_response = bs4.BeautifulSoup(ondemand_file.content, 'html.parser')
# Getting "Couldn't get KEY_BYTE indices" error? Try passing the original response or the response text
# both should work
# ondemand_file_response = ondemand_file
ondemand_file_response = ondemand_file.text
Generate X-Client-Transaction-Id (tid):
from urllib.parse import urlparse
from x_client_transaction import ClientTransaction
# 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(home_page_response=home_page_response, ondemand_file_response=ondemand_file_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)
Authors
Feedback
If you have any feedback, please reach out to us at hello@sarabjitdhiman.com or contact me on Social Media @iSarabjitDhiman
Support
For support, email hello@sarabjitdhiman.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file fork_xclienttransaction-1.0.3.tar.gz.
File metadata
- Download URL: fork_xclienttransaction-1.0.3.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
758edd6ef5224672a2d37b281365169eeea9c32108891fee1d3a4abfa5e35de6
|
|
| MD5 |
dc1fbbf6a17f804be27d15185f25a104
|
|
| BLAKE2b-256 |
ad17785454f41a07516eb685cb95c62e48d34798a00fe2e5cc416b43ec1a6b09
|