-
-
Save garoto/e56a68b8944a1e9293f8c8deb4bfd2e9 to your computer and use it in GitHub Desktop.
Grab oauth token for use with Nitter (requires Twitter account)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Grab oauth token for use with Nitter (requires Twitter account). | |
| # results: [{"oauth_token":"xxxxxxxxxx-xxxxxxxxx","oauth_token_secret":"xxxxxxxxxxxxxxxxxxxxx"}] | |
| username="" | |
| password="" | |
| if [[ -z "$username" || -z "$password" ]]; then | |
| echo "requires username and password" | |
| exit 1 | |
| fi | |
| bearer_token='AAAAAAAAAAAAAAAAAAAAAFXzAwAAAAAAMHCxpeSDG1gLNLghVe8d74hl6k4%3DRUMF4xAQLsbeBhTSRrCiQpJtxoGWeyHrDb5te2jpGskWDFW82F' | |
| guest_token=$(curl -s -XPOST https://api.twitter.com/1.1/guest/activate.json -H "Authorization: Bearer ${bearer_token}" -H 'Connection: close' | jq -r '.guest_token') | |
| task_1=$(curl -s -v -XPOST 'https://api.twitter.com/1.1/onboarding/task.json?flow_name=login&api_version=1&known_device_token=&sim_country_code=us' \ | |
| -H "Authorization: Bearer ${bearer_token}" \ | |
| -H 'Content-Type: application/json' \ | |
| -H 'User-Agent: TwitterAndroid/10.21.1' \ | |
| -H "X-Guest-Token: ${guest_token}" \ | |
| -d '{"flow_token": null, "input_flow_data": {"country_code": null, "flow_context": {"referrer_context": {"referral_details": "utm_source=google-play&utm_medium=organic", "referrer_url": ""}, "start_location": {"location": "deeplink"}}, "requested_variant": null, "target_user_id": 0}}' 2>&1) | |
| att=$(sed -En 's/.*att: (.*)/\1/p' <<< ${task_1}) | |
| flow_token=$(sed -En 's/(.*flow_token.*)/\1/p' <<< ${task_1} | jq -r .flow_token) | |
| token_2=$(curl -s -XPOST 'https://api.twitter.com/1.1/onboarding/task.json' \ | |
| -H "att: ${att}" \ | |
| -H "Authorization: Bearer ${bearer_token}" \ | |
| -H 'Content-Type: application/json' \ | |
| -H 'User-Agent: TwitterAndroid/10.21.1' \ | |
| -H "X-Guest-Token: ${guest_token}" \ | |
| -d "{\"flow_token\": \"${flow_token}\", \"subtask_inputs\": [{\"enter_text\": {\"suggestion_id\": null, \"text\": \"${username}\", \"link\": \"next_link\"}, \"subtask_id\": \"LoginEnterUserIdentifier\"}]}" | jq -r .flow_token) | |
| token_3=$(curl -s -XPOST 'https://api.twitter.com/1.1/onboarding/task.json' \ | |
| -H "att: ${att}" \ | |
| -H "Authorization: Bearer ${bearer_token}" \ | |
| -H 'Content-Type: application/json' \ | |
| -H 'User-Agent: TwitterAndroid/10.21.1' \ | |
| -H "X-Guest-Token: ${guest_token}" \ | |
| -d "{\"flow_token\": \"${token_2}\", \"subtask_inputs\": [{\"enter_password\": {\"password\": \"${password}\", \"link\": \"next_link\"}, \"subtask_id\": \"LoginEnterPassword\"}]}" | jq -r .flow_token) | |
| curl -s -XPOST 'https://api.twitter.com/1.1/onboarding/task.json' \ | |
| -H "att: ${att}" \ | |
| -H "Authorization: Bearer ${bearer_token}" \ | |
| -H 'Content-Type: application/json' \ | |
| -H 'User-Agent: TwitterAndroid/10.21.1' \ | |
| -H "X-Guest-Token: ${guest_token}" \ | |
| -d "{\"flow_token\": \"${token_3}\", \"subtask_inputs\": [{\"check_logged_in_account\": {\"link\": \"AccountDuplicationCheck_false\"}, \"subtask_id\": \"AccountDuplicationCheck\"}]}" | jq -c '.subtasks[0]|if(.open_account) then [{oauth_token: .open_account.oauth_token, oauth_token_secret: .open_account.oauth_token_secret}] else empty end' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment