fix: twitter plugin (#16)

This commit is contained in:
tsukino
2025-01-15 09:42:28 -05:00
committed by GitHub
parent 73c2d3744f
commit 0f95bda1fa
2 changed files with 12 additions and 8 deletions

View File

@@ -25,10 +25,10 @@
"notarize" "notarize"
], ],
"cookies": [ "cookies": [
"api.x.com" "https://api.x.com/1.1/account/settings.json"
], ],
"headers": [ "headers": [
"api.x.com" "https://api.x.com/1.1/account/settings.json"
], ],
"requests": [ "requests": [
{ {

View File

@@ -40,34 +40,38 @@ export function start() {
* Note that the url needs to be specified in the `config` too, otherwise the request will be refused. * Note that the url needs to be specified in the `config` too, otherwise the request will be refused.
*/ */
export function two() { export function two() {
const cookies = getCookiesByHost('api.x.com'); const cookies = getCookiesByHost('https://api.x.com/1.1/account/settings.json');
const headers = getHeadersByHost('api.x.com'); const headers = getHeadersByHost('https://api.x.com/1.1/account/settings.json');
if ( if (
!cookies.auth_token || !cookies.auth_token ||
!cookies.ct0 || !cookies.ct0 ||
!headers['x-csrf-token'] || !headers['x-csrf-token'] ||
!headers['authorization'] !headers['authorization'] ||
!headers['x-client-transaction-id']
) { ) {
outputJSON(false); outputJSON(false);
return; return;
} }
const cookieString = Object.entries(cookies).map(([name, value]) => `${name}=${value}`).join('; ')
outputJSON({ outputJSON({
url: 'https://api.x.com/1.1/account/settings.json', url: 'https://api.x.com/1.1/account/settings.json',
method: 'GET', method: 'GET',
headers: { headers: {
'x-twitter-client-language': 'en', Cookie: cookieString,
'x-csrf-token': headers['x-csrf-token'], 'x-csrf-token': headers['x-csrf-token'],
'x-client-transaction-id': headers['x-client-transaction-id'],
Host: 'api.x.com', Host: 'api.x.com',
authorization: headers.authorization, authorization: headers.authorization,
Cookie: `lang=en; auth_token=${cookies.auth_token}; ct0=${cookies.ct0}`,
'Accept-Encoding': 'identity', 'Accept-Encoding': 'identity',
Connection: 'close', Connection: 'close',
}, },
secretHeaders: [ secretHeaders: [
`x-csrf-token: ${headers['x-csrf-token']}`, `x-csrf-token: ${headers['x-csrf-token']}`,
`cookie: lang=en; auth_token=${cookies.auth_token}; ct0=${cookies.ct0}`, `x-client-transaction-id: ${headers['x-client-transaction-id']}`,
`cookie: ${cookieString}`,
`authorization: ${headers.authorization}`, `authorization: ${headers.authorization}`,
], ],
}); });