Skip to content

fix--keep-alive-option#57

Open
grantdfoster wants to merge 4 commits intoimperatrona:masterfrom
masa-finance:fix--keep-alive-option
Open

fix--keep-alive-option#57
grantdfoster wants to merge 4 commits intoimperatrona:masterfrom
masa-finance:fix--keep-alive-option

Conversation

@grantdfoster
Copy link

No description provided.

grantdfoster and others added 4 commits July 15, 2025 11:29
* feat: implement native Go x-client-transaction-id generation

This PR implements native Go generation of the x-client-transaction-id header
required by Twitter/X's updated API security.

## Changes

### New Files
- x_transaction.go: Core transaction ID generation logic ported from Python
- x_cubic.go: Cubic Bézier interpolation for animation calculations
- x_utils.go: Helper functions (floatToHex, interpolate, rotation matrix)

### Modified Files
- api.go: Integrate transaction ID generation into authenticated requests
- auth.go: Update bearer tokens for new API endpoints
- auth_test.go: Support loading cookies from cookies.json file
- scraper.go: Add transaction context caching struct
- search.go: Update GraphQL endpoint and feature flags for x.com
- account.go: Update API endpoints to api.x.com
- util.go: Update base URL to x.com
- search_test.go: Reduce test tweet counts (150 -> 10) to avoid rate limits
- tweets_test.go: Reduce test tweet counts (150 -> 10) to avoid rate limits
- .gitignore: Add cookies.json to prevent accidental commits

## Technical Details

The x-client-transaction-id header is generated by:
1. Fetching x.com homepage to extract verification key and SVG animation data
2. Parsing ondemand.s.*.js to get key byte indices
3. Computing animation key via cubic Bézier interpolation
4. Hashing with SHA256 using method, path, timestamp, and animation key
5. XOR encoding with random byte and base64 encoding

The transaction context (verification key + animation key) is cached for 10 minutes
to avoid fetching the homepage on every request. The actual transaction ID is
unique per request due to timestamp and random components.

## Testing
- All search tests pass with native Go implementation
- No Python dependency required

* refactor: remove unused features and simplify tests

## Removed Features (per issue requirements)
- Bookmarks (bookmarks.go)
- Followers/Following (follows.go)
- Spaces (spaces.go)
- Scheduled tweets (schedule.go)
- Media timeline (medias.go)
- Media upload (upload.go)
- Home/ForYou timeline (from tweets.go)
- Tweet creation/deletion/like/retweet (from tweet.go)
- Login/LoginOpenAccount methods (from auth.go)

## Authentication Changes
- IsLoggedIn() now only checks for auth_token cookie presence
- No longer hits Twitter endpoints to verify login status
- Removed username/password login support
- Cookie-based authentication only

## Endpoint Updates
All endpoints updated to x.com/api.x.com:
- profile.go: UserByScreenName, UserByRestId
- trends.go: guide.json
- replies.go: TweetDetail
- tweets.go: All timeline endpoints
- api.go: guest/activate

## Test Simplification
- Simplified all tests to verify functionality only
- Removed tests that relied on specific tweet content
- Removed tests for deleted features
- All tests now pass reliably

* chore: final audit and cleanup

## Code Cleanup
- Removed unused Scraper fields: isOpenAccount, oAuthToken, oAuthSecret, includeReplies
- Removed OAuth signing code (no longer needed for cookie-only auth)
- Removed FetchTweetsByUserIDLegacy function (only used with OpenAccount)
- Removed commented-out code
- Simplified GetTweet to remove isOpenAccount branch

## Updates
- Updated User-Agent to Chrome 131 (December 2024)
- Added missing feature flags (rweb_lists_timeline_redesign_enabled, tweetypie_unmention_optimization_enabled)
- Standardized feature flags across all endpoints
- Simplified auth.go (removed unused logout API call, cleaner cookie handling)

## Best Practices
- All endpoints use api.x.com
- All feature flags are current as of December 2024
- Bearer token is consistent across all requests
- Transaction ID caching implemented (10 minute TTL)

All 19 tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants