mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-15 10:15:23 +08:00
fix(route/twitter): Web API authentication (#12754)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const twitterGot = require('./twitter-got');
|
||||
const { graphQLMap, featuresMap } = require('./constants');
|
||||
const config = require('@/config').value;
|
||||
|
||||
// https://github.com/mikf/gallery-dl/blob/a53cfc845e12d9e98fefd07e43ebffaec488c18f/gallery_dl/extractor/twitter.py#L727-L755
|
||||
@@ -65,6 +66,7 @@ const paginationTweets = async (endpoint, userId, variables, path) => {
|
||||
...variables,
|
||||
userId,
|
||||
}),
|
||||
features: featuresMap.UserTweets,
|
||||
});
|
||||
|
||||
let instructions;
|
||||
@@ -81,24 +83,24 @@ const paginationTweets = async (endpoint, userId, variables, path) => {
|
||||
|
||||
// https://github.com/mikf/gallery-dl/blob/a53cfc845e12d9e98fefd07e43ebffaec488c18f/gallery_dl/extractor/twitter.py#L807-L814
|
||||
const timelineTweets = (userId, params = {}) =>
|
||||
paginationTweets('/graphql/WZT7sCTrLvSOaWOXLDsWbQ/UserTweets', userId, {
|
||||
paginationTweets(graphQLMap.UserTweets, userId, {
|
||||
...params,
|
||||
withQuickPromoteEligibilityTweetFields: true,
|
||||
});
|
||||
|
||||
// https://github.com/mikf/gallery-dl/blob/a53cfc845e12d9e98fefd07e43ebffaec488c18f/gallery_dl/extractor/twitter.py#L816-L823
|
||||
const timelineTweetsAndReplies = (userId, params = {}) =>
|
||||
paginationTweets('/graphql/t4wEKVulW4Mbv1P0kgxTEw/UserTweetsAndReplies', userId, {
|
||||
paginationTweets(graphQLMap.UserTweetsAndReplies, userId, {
|
||||
...params,
|
||||
withCommunity: true,
|
||||
});
|
||||
|
||||
// https://github.com/mikf/gallery-dl/blob/a53cfc845e12d9e98fefd07e43ebffaec488c18f/gallery_dl/extractor/twitter.py#L825-L831
|
||||
const timelineMedia = (userId, params = {}) => paginationTweets('/graphql/nRybED9kRbN-TOWioHq1ng/UserMedia', userId, params);
|
||||
const timelineMedia = (userId, params = {}) => paginationTweets(graphQLMap.UserMedia, userId, params);
|
||||
|
||||
// this query requires login
|
||||
// https://github.com/mikf/gallery-dl/blob/a53cfc845e12d9e98fefd07e43ebffaec488c18f/gallery_dl/extractor/twitter.py#L833-L839
|
||||
const timelineLikes = (userId, params = {}) => paginationTweets(`/graphql/9MSTt44HoGjVFSg_u3rHDw/Likes`, userId, params);
|
||||
const timelineLikes = (userId, params = {}) => paginationTweets(graphQLMap.Likes, userId, params);
|
||||
|
||||
// https://github.com/mikf/gallery-dl/blob/a53cfc845e12d9e98fefd07e43ebffaec488c18f/gallery_dl/extractor/twitter.py#L858-L866
|
||||
const timelineKeywords = (keywords, params = {}) =>
|
||||
@@ -114,7 +116,7 @@ const timelineKeywords = (keywords, params = {}) =>
|
||||
// https://github.com/mikf/gallery-dl/blob/a53cfc845e12d9e98fefd07e43ebffaec488c18f/gallery_dl/extractor/twitter.py#L795-L805
|
||||
const tweetDetail = (userId, params) =>
|
||||
paginationTweets(
|
||||
'/graphql/ItejhtHVxU7ksltgMmyaLA/TweetDetail',
|
||||
graphQLMap.TweetDetail,
|
||||
userId,
|
||||
{
|
||||
...params,
|
||||
@@ -225,12 +227,13 @@ const excludeRetweet = function (tweets) {
|
||||
};
|
||||
|
||||
const userByScreenName = (screenName) =>
|
||||
twitterGot('https://twitter.com/i/api/graphql/hc-pka9A7gyS3xODIafnrQ/UserByScreenName', {
|
||||
twitterGot(`https://twitter.com/i/api${graphQLMap.UserByScreenName}`, {
|
||||
variables: `{"screen_name":"${screenName}","withHighlightedLabel":true}`,
|
||||
features: featuresMap.UserByScreenName,
|
||||
});
|
||||
const getUserData = (cache, screenName) => cache.tryGet(`twitter-userdata-${screenName}`, () => userByScreenName(screenName));
|
||||
const getUserID = async (cache, screenName) => (await getUserData(cache, screenName)).data.user.rest_id;
|
||||
const getUser = async (cache, screenName) => (await getUserData(cache, screenName)).data.user.legacy;
|
||||
const getUserID = async (cache, screenName) => (await getUserData(cache, screenName)).data.user.result.rest_id;
|
||||
const getUser = async (cache, screenName) => (await getUserData(cache, screenName)).data.user.result.legacy;
|
||||
|
||||
const cacheTryGet = async (cache, screenName, params, func) => {
|
||||
const id = await getUserID(cache, screenName);
|
||||
|
||||
Reference in New Issue
Block a user