From b2e75dbf426c5addfbd5245f63ab0179624d2fb8 Mon Sep 17 00:00:00 2001 From: Daniel Lindau <35381223+d-lindau@users.noreply.github.com> Date: Tue, 30 Jul 2024 19:57:11 +0200 Subject: [PATCH 1/3] Corrected getFollows endpoint --- src/index.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index cc075e3..13f0026 100644 --- a/src/index.ts +++ b/src/index.ts @@ -461,11 +461,22 @@ export class TwitchApi extends EventEmitter{ */ async getFollows(options?: GetFollowsOptions): Promise{ let query = "?"; + let endpoint = "/channels/"; - if(options) + if(options){ query += parseOptions(options); - const endpoint = `/users/follows${query}`; + if(options.to_id) + { + endpoint += "followers"; + + }else if(options.from_id) + { + endpoint += "followed"; + } + } + + endpoint = endpoint + query; return this._get(endpoint); } From 20be9b6b9021fb7854a175974d2ad60954cda3a0 Mon Sep 17 00:00:00 2001 From: Daniel Lindau <35381223+d-lindau@users.noreply.github.com> Date: Tue, 30 Jul 2024 20:21:55 +0200 Subject: [PATCH 2/3] Update options.ts --- src/types/options.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/types/options.ts b/src/types/options.ts index eeb2cad..f68944f 100644 --- a/src/types/options.ts +++ b/src/types/options.ts @@ -27,18 +27,18 @@ export interface TwitchApiConfig{ } /** The options to customize the request. */ -export interface GetFollowsOptions{ +export interface GetFollowersOptions{ /** Cursor for forward pagination: tells the server where to start fetching the next set of results, in a multi-page response. The cursor value specified here is from the pagination response field of a prior query. */ after?: string; /** Maximum number of objects to return. Maximum: 100. Default: 20. */ first?: number; - /** User ID. Return list of channels that the supplied user is following. */ - from_id?: string | number; + /** The broadcaster’s ID. Returns the list of users that follow this broadcaster. */ + broadcaster_id?: string | number; - /** User ID. Return list of users who are following the supplied channel. */ - to_id?: string | number; + /** Use this parameter to see whether the user follows this broadcaster. If specified, the response contains this user if they follow the broadcaster. If not specified, the response contains all users that follow the broadcaster. */ + user_id?: string | number; } /** An options object used to create the request. */ From c022f45343b34f7887458d3030bb96c3d18b299d Mon Sep 17 00:00:00 2001 From: Daniel Lindau <35381223+d-lindau@users.noreply.github.com> Date: Tue, 30 Jul 2024 20:22:06 +0200 Subject: [PATCH 3/3] Update index.ts --- src/index.ts | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/index.ts b/src/index.ts index 13f0026..ac1cee4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,7 +11,7 @@ import { BaseOptions, GetAllStreamTagsOptions, GetBitsLeaderboardOptions, - GetFollowsOptions, + GetFollowersOptions, GetStreamsOptions, GetVideosOptions, GetSubsOptions, @@ -456,27 +456,15 @@ export class TwitchApi extends EventEmitter{ return this._get(endpoint); } - /** Get follows to or from a channel. Must provide either from_id or to_id. - * @deprecated Twitch has remove this endpoint. - */ - async getFollows(options?: GetFollowsOptions): Promise{ + /** Get followers of a channel */ + async getFollowers(options?: GetFollowersOptions): Promise{ let query = "?"; - let endpoint = "/channels/"; if(options){ - query += parseOptions(options); - - if(options.to_id) - { - endpoint += "followers"; - - }else if(options.from_id) - { - endpoint += "followed"; - } + query += parseOptions(options); } - endpoint = endpoint + query; + const endpoint = `/channels/followers${query}`; return this._get(endpoint); }