diff --git a/docs/en/install/README.md b/docs/en/install/README.md index 53e95dcd3..5d73ef16e 100644 --- a/docs/en/install/README.md +++ b/docs/en/install/README.md @@ -858,7 +858,7 @@ See docs of the specified route and `lib/config.js` for detailed information. - `TWITTER_CONSUMER_KEY`: Twitter Developer API key, support multiple keys, split them with `,` - `TWITTER_CONSUMER_SECRET`: Twitter Developer API key secret, support multiple keys, split them with `,` - - `TWITTER_WEBAPI_AUTHORIZAION`: Twitter Web API authorization, in format `key:secret`, support multiple ones, split them with `,`. If either of the above environment variables is not set, the Twitter Web API will be used. However, no need to set this environment var since currently known tokens have already been built into RSSHub. + - `TWITTER_WEBAPI_AUTHORIZAION`: Twitter Web API authorization, in format `key:secret` or `Bearer ****`, support multiple ones, split them with `,`. If either of the above environment variables is not set, the Twitter Web API will be used. However, no need to set this environment var since currently known tokens have already been built into RSSHub. - `TWITTER_TOKEN_{handler}`: The token generated by the corresponding Twitter handler, replace `{handler}` with the Twitter handler, the value is a combination of `Twitter API key, Twitter API key secret, Access token, Access token secret` connected by a comma `,`. Eg. `TWITTER_TOKEN_RSSHub=bX1zry5nG4d1RbESQbnADpVIo,2YrD8qo9sXbB8VlYfVmo1Qtw0xsexnOliU5oZofq7aPIGou0Xx,123456789-hlkUHFYmeXrRcf6SEQciP8rP4lzmRgMgwdqIN9aK,pHcPnfa28rCIKhSICUCiaw9ppuSSl7T2f3dnGYpSM0bod`. - Wordpress: diff --git a/docs/install/README.md b/docs/install/README.md index 818abce2c..801d5db45 100644 --- a/docs/install/README.md +++ b/docs/install/README.md @@ -902,7 +902,7 @@ RSSHub 支持使用访问密钥 / 码,白名单和黑名单三种方式进行 - `TWITTER_CONSUMER_KEY`: Twitter Developer API key,支持多个 key,用英文逗号 `,` 隔开 - `TWITTER_CONSUMER_SECRET`: Twitter Developer API key secret,支持多个 key,用英文逗号 `,` 隔开,顺序与 key 对应 - - `TWITTER_WEBAPI_AUTHORIZAION`: Twitter Web API authorization,格式为 `key:secret`,支持多个,用英文逗号 `,` 隔开。如果上述两个环境变量中的任意一个未设置,就会使用 Twitter Web API。然而,没有必要设置这个环境变量,因为 RSSHub 已经内置了目前已知可用的 token。 + - `TWITTER_WEBAPI_AUTHORIZAION`: Twitter Web API authorization,格式为 `key:secret` 或 `Bearer ****`,支持多个,用英文逗号 `,` 隔开。如果上述两个环境变量中的任意一个未设置,就会使用 Twitter Web API。然而,没有必要设置这个环境变量,因为 RSSHub 已经内置了目前已知可用的 token。 - `TWITTER_TOKEN_{handler}`: 对应 Twitter 用户名生成的 token,`{handler}` 替换为用于生成该 token 的 Twitter 用户名,值为 `Twitter API key, Twitter API key secret, Access token, Access token secret` 用逗号隔开,例如:`TWITTER_TOKEN_RSSHub=bX1zry5nG4d1RbESQbnADpVIo,2YrD8qo9sXbB8VlYfVmo1Qtw0xsexnOliU5oZofq7aPIGou0Xx,123456789-hlkUHFYmeXrRcf6SEQciP8rP4lzmRgMgwdqIN9aK,pHcPnfa28rCIKhSICUCiaw9ppuSSl7T2f3dnGYpSM0bod` - Wordpress diff --git a/lib/v2/twitter/web-api/constants.js b/lib/v2/twitter/web-api/constants.js index 65d36deb0..b0245649d 100644 --- a/lib/v2/twitter/web-api/constants.js +++ b/lib/v2/twitter/web-api/constants.js @@ -1,8 +1,10 @@ // https://github.com/zedeus/nitter/issues/919#issuecomment-1619067142 -// https://git.sr.ht/~cloutier/bird.makeup/tree/087a8e3e98b642841dde84465c19121fc3b4c6ee/item/src/BirdsiteLive.Twitter/Tools/TwitterAuthenticationInitializer.cs#L36 +// https://git.sr.ht/~cloutier/bird.makeup/tree/4b2495bf2908c648ae9250f353bfdacf2464b98d/item/src/BirdsiteLive.Twitter/Tools/TwitterAuthenticationInitializer.cs#L36 +const auth = 'Bearer AAAAAAAAAAAAAAAAAAAAAFQODgEAAAAAVHTp76lzh3rFzcHbmHVvQxYYpTw%3DckAlMINMjmCwxUcaXbAN4XqJVdgMJaHqNOFgPMK0zN1qLqLQCF'; const tokens = [ - 'CjulERsDeqhhjSme66ECg:IQWdVyqFxghAtURHGeGiWAsmCAGmdW3WmbEx6Hck', // iPad - // valid, but endpoints differ + auth, // tweetdeck new + // 'CjulERsDeqhhjSme66ECg:IQWdVyqFxghAtURHGeGiWAsmCAGmdW3WmbEx6Hck', // iPad, no mixed videos and photos support + // valid, but endpoints differ: // 'IQKbtAYlXLripLGPWd0HUA:GgDYlkSvaPxGxC4X8liwpUoqKwwr3lCADbz8A7ADU', // iPhone // '3nVuSoBZnx6U4vzUxf5w:Bcs59EFbbsdF6Sl9Ng71smgStWEGwXXKSjYvPVt7qys', // Android // '3rJOl1ODzm9yZy63FACdg:5jPoQ5kQvMJFDYRNE8bQ4rHuds4xJqhvgNJM4awaE8', // Mac @@ -67,11 +69,9 @@ const featuresMap = { }), }; -const auth = 'Bearer AAAAAAAAAAAAAAAAAAAAAFQODgEAAAAAVHTp76lzh3rFzcHbmHVvQxYYpTw%3DckAlMINMjmCwxUcaXbAN4XqJVdgMJaHqNOFgPMK0zN1qLqLQCF'; - module.exports = { + auth, tokens, graphQLMap, featuresMap, - auth, }; diff --git a/lib/v2/twitter/web-api/twitter-got.js b/lib/v2/twitter/web-api/twitter-got.js index 96720ab28..0b68af1b3 100644 --- a/lib/v2/twitter/web-api/twitter-got.js +++ b/lib/v2/twitter/web-api/twitter-got.js @@ -47,13 +47,17 @@ async function resetSession() { setCookie = promisify(cookieJar.setCookie.bind(cookieJar)); let response; // auth - headers.authorization = `Basic ${Buffer.from(tokens[tries++ % tokens.length]).toString('base64')}`; - response = await twitterGot({ - url: 'https://api.twitter.com/oauth2/token', - method: 'POST', - searchParams: queryString.stringify({ grant_type: 'client_credentials' }), - }); - headers.authorization = `Bearer ${response.data.access_token}`; + let token = tokens[tries++ % tokens.length]; + if (!token.startsWith('Bearer')) { + headers.authorization = `Basic ${Buffer.from(token).toString('base64')}`; + response = await twitterGot({ + url: 'https://api.twitter.com/oauth2/token', + method: 'POST', + searchParams: queryString.stringify({ grant_type: 'client_credentials' }), + }); + token = `Bearer ${response.data.access_token}`; + } + headers.authorization = token; // 生成csrf-token const csrfToken = [...Array(16 * 2)].map(() => Math.floor(Math.random() * 16).toString(16)).join(''); await setCookie(new Cookie({ key: 'ct0', value: csrfToken, domain: cookiedomain, secure: false }), cookieurl);