Skip to content

Commit 75d8152

Browse files
authored
fix(route): fix /twitter/likes (#15384)
* fix(route): fix /twitter/likes * fix: delete not used variables * update: router /twitter/likes config * feat: throw a error for Twitter Premium accounts. * feat: throw a error for Twitter Premium accounts
1 parent 41a8eec commit 75d8152

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

lib/routes/twitter/api/web-api/api.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,20 @@ const getUserMedia = (id: string, params?: Record<string, any>) =>
9797
);
9898
});
9999

100-
const getUserLikes = (id: string, params?: Record<string, any>) => cacheTryGet(id, params, async (id, params = {}) => gatherLegacyFromData(await paginationTweets('Likes', id, params)));
100+
const getUserLikes = (id: string, params?: Record<string, any>) =>
101+
cacheTryGet(id, params, async (id, params = {}) =>
102+
gatherLegacyFromData(
103+
await paginationTweets(
104+
'Likes',
105+
id,
106+
{
107+
...params,
108+
includeHasBirdwatchNotes: false,
109+
includePromotedContent: false,
110+
withBirdwatchNotes: false,
111+
withVoice: false,
112+
withV2Timeline: true,
113+
})));
101114

102115
const getUserTweet = (id: string, params?: Record<string, any>) =>
103116
cacheTryGet(id, params, async (id, params = {}) =>

lib/routes/twitter/api/web-api/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ const gqlFeatures = {
8888
ListLatestTweetsTimeline: gqlFeatureFeed,
8989
HomeTimeline: gqlFeatureFeed,
9090
TweetDetail: TweetDetailFeatures,
91+
Likes: gqlFeatureFeed
9192
};
9293

9394
const timelineParams = {

lib/routes/twitter/api/web-api/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ export const paginationTweets = async (endpoint: string, userId: number | undefi
6363
}
6464
instructions = instructions.instructions;
6565
} else {
66-
instructions = data.user.result.timeline_v2.timeline.instructions;
66+
if (data?.user?.result?.timeline_v2?.timeline?.instructions) {
67+
instructions = data.user.result.timeline_v2.timeline.instructions;
68+
} else {
69+
throw new Error('Because Twitter Premium has features that hide your likes, this RSS link is not available for Twitter Premium accounts.');
70+
}
6771
}
6872

6973
const entries1 = instructions.find((i) => i.type === 'TimelineAddToModule')?.moduleItems; // Media

lib/routes/twitter/likes.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import { Route } from '@/types';
22
import utils from './utils';
3-
import { config } from '@/config';
4-
import ConfigNotFoundError from '@/errors/types/config-not-found';
3+
import api from './api';
54

65
export const route: Route = {
76
path: '/likes/:id/:routeParams?',
87
categories: ['social-media'],
98
example: '/twitter/likes/DIYgod',
109
parameters: { id: 'username', routeParams: 'extra parameters, see the table above' },
1110
features: {
12-
requireConfig: false,
11+
requireConfig: [
12+
{
13+
name: 'TWITTER_COOKIE',
14+
description: 'Please see above for details.',
15+
},
16+
],
1317
requirePuppeteer: false,
1418
antiCrawler: false,
1519
supportBT: false,
@@ -22,15 +26,15 @@ export const route: Route = {
2226
};
2327

2428
async function handler(ctx) {
25-
if (!config.twitter || !config.twitter.consumer_key || !config.twitter.consumer_secret) {
26-
throw new ConfigNotFoundError('Twitter RSS is disabled due to the lack of <a href="https://docs.rsshub.app/deploy/config#route-specific-configurations">relevant config</a>');
27-
}
2829
const id = ctx.req.param('id');
29-
const client = await utils.getAppClient();
30-
const data = await client.v1.get('favorites/list.json', {
31-
screen_name: id,
32-
tweet_mode: 'extended',
33-
});
30+
const { count, include_rts } = utils.parseRouteParams(ctx.req.param('routeParams'));
31+
const params = count ? { count } : {};
32+
33+
await api.init();
34+
let data = await api.getUserLikes(id, params);
35+
if (!include_rts) {
36+
data = utils.excludeRetweet(data);
37+
}
3438

3539
return {
3640
title: `Twitter Likes - ${id}`,

0 commit comments

Comments
 (0)