-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add twitter token generation script
- Loading branch information
Showing
6 changed files
with
155 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,5 @@ package-lock.json | |
# pnpm-lock.yaml | ||
yarn.lock | ||
yarn-error.log | ||
|
||
scripts/twitter-token/accounts.txt |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
const got = require('got'); | ||
const { HttpsProxyAgent } = require('https-proxy-agent'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const concurrency = 5; // Please do not set it too large to avoid Twitter discovering our little secret | ||
const proxyUrl = ''; // Add your proxy here | ||
|
||
const baseURL = 'https://api.twitter.com/1.1/'; | ||
const headers = { | ||
Authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAAFXzAwAAAAAAMHCxpeSDG1gLNLghVe8d74hl6k4%3DRUMF4xAQLsbeBhTSRrCiQpJtxoGWeyHrDb5te2jpGskWDFW82F', | ||
'User-Agent': 'TwitterAndroid/10.10.0', | ||
}; | ||
|
||
const accounts = []; | ||
|
||
function generateOne() { | ||
// eslint-disable-next-line no-async-promise-executor | ||
return new Promise(async (resolve) => { | ||
const timeout = setTimeout(() => { | ||
// eslint-disable-next-line no-console | ||
console.log(`Failed to generate account, continue... timeout`); | ||
resolve(); | ||
}, 30000); | ||
|
||
const agent = { | ||
https: proxyUrl && new HttpsProxyAgent(proxyUrl), | ||
}; | ||
|
||
try { | ||
const response = await got.post(`${baseURL}guest/activate.json`, { | ||
headers: { | ||
Authorization: headers.Authorization, | ||
}, | ||
agent, | ||
timeout: { | ||
request: 20000, | ||
}, | ||
}); | ||
const guestToken = JSON.parse(response.body).guest_token; | ||
|
||
const flowResponse = await got.post(`${baseURL}onboarding/task.json?flow_name=welcome`, { | ||
json: { | ||
flow_token: null, | ||
input_flow_data: { | ||
flow_context: { | ||
start_location: { | ||
location: 'splash_screen', | ||
}, | ||
}, | ||
}, | ||
}, | ||
headers: { | ||
...headers, | ||
'X-Guest-Token': guestToken, | ||
}, | ||
agent, | ||
timeout: { | ||
request: 20000, | ||
}, | ||
}); | ||
const flowToken = JSON.parse(flowResponse.body).flow_token; | ||
|
||
const finalResponse = await got.post(`${baseURL}onboarding/task.json`, { | ||
json: { | ||
flow_token: flowToken, | ||
subtask_inputs: [ | ||
{ | ||
open_link: { | ||
link: 'next_link', | ||
}, | ||
subtask_id: 'NextTaskOpenLink', | ||
}, | ||
], | ||
}, | ||
headers: { | ||
...headers, | ||
'X-Guest-Token': guestToken, | ||
}, | ||
agent, | ||
timeout: { | ||
request: 20000, | ||
}, | ||
}); | ||
|
||
const account = JSON.parse(finalResponse.body).subtasks[0].open_account; | ||
|
||
if (account) { | ||
accounts.push({ | ||
t: account.oauth_token, | ||
s: account.oauth_token_secret, | ||
}); | ||
} else { | ||
// eslint-disable-next-line no-console | ||
console.log(`Failed to generate account, continue... no account`); | ||
} | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.log(`Failed to generate account, continue... ${error}`); | ||
} | ||
|
||
clearTimeout(timeout); | ||
resolve(); | ||
}); | ||
} | ||
|
||
(async () => { | ||
const oldAccounts = fs.readFileSync(path.join(__dirname, 'accounts.txt')); | ||
const tokens = oldAccounts.toString().split('\n')[0].split('=')[1].split(','); | ||
const secrets = oldAccounts.toString().split('\n')[1].split('=')[1].split(','); | ||
for (let i = 0; i < tokens.length; i++) { | ||
accounts.push({ | ||
t: tokens[i], | ||
s: secrets[i], | ||
}); | ||
} | ||
|
||
for (let i = 0; i < 1000; i++) { | ||
// eslint-disable-next-line no-console | ||
console.log(`Generating accounts ${i * concurrency}-${(i + 1) * concurrency - 1}, total ${accounts.length}`); | ||
|
||
// eslint-disable-next-line no-await-in-loop | ||
await Promise.all(Array.from({ length: concurrency }, () => generateOne())); | ||
fs.writeFileSync(path.join(__dirname, 'accounts.txt'), [`TWITTER_OAUTH_TOKEN=${accounts.map((account) => account.t).join(',')}`, `TWITTER_OAUTH_TOKEN_SECRET=${accounts.map((account) => account.s).join(',')}`].join('\n')); | ||
} | ||
})(); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
guest_token=$(curl -s -XPOST https://api.twitter.com/1.1/guest/activate.json -H 'Authorization: Bearer AAAAAAAAAAAAAAAAAAAAAFXzAwAAAAAAMHCxpeSDG1gLNLghVe8d74hl6k4%3DRUMF4xAQLsbeBhTSRrCiQpJtxoGWeyHrDb5te2jpGskWDFW82F' | jq -r '.guest_token') | ||
|
||
flow_token=$(curl -s -XPOST 'https://api.twitter.com/1.1/onboarding/task.json?flow_name=welcome' \ | ||
-H 'Authorization: Bearer AAAAAAAAAAAAAAAAAAAAAFXzAwAAAAAAMHCxpeSDG1gLNLghVe8d74hl6k4%3DRUMF4xAQLsbeBhTSRrCiQpJtxoGWeyHrDb5te2jpGskWDFW82F' \ | ||
-H 'Content-Type: application/json' \ | ||
-H "User-Agent: TwitterAndroid/10.10.0" \ | ||
-H "X-Guest-Token: ${guest_token}" \ | ||
-d '{"flow_token":null,"input_flow_data":{"flow_context":{"start_location":{"location":"splash_screen"}}}}' | jq -r .flow_token) | ||
|
||
curl -s -XPOST 'https://api.twitter.com/1.1/onboarding/task.json' \ | ||
-H 'Authorization: Bearer AAAAAAAAAAAAAAAAAAAAAFXzAwAAAAAAMHCxpeSDG1gLNLghVe8d74hl6k4%3DRUMF4xAQLsbeBhTSRrCiQpJtxoGWeyHrDb5te2jpGskWDFW82F' \ | ||
-H 'Content-Type: application/json' \ | ||
-H "User-Agent: TwitterAndroid/10.10.0" \ | ||
-H "X-Guest-Token: ${guest_token}" \ | ||
-d "{\"flow_token\":\"${flow_token}\",\"subtask_inputs\":[{\"open_link\":{\"link\":\"next_link\"},\"subtask_id\":\"NextTaskOpenLink\"}]}" | jq -c -r '.subtasks[0]|if(.open_account) then {oauth_token: .open_account.oauth_token, oauth_token_secret: .open_account.oauth_token_secret} else empty end' |
This file contains 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
This file contains 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
This file contains 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