Last active
August 25, 2023 10:14
-
-
Save gNaps/f3a9669172cabae89b949ebd3e5c49dd to your computer and use it in GitHub Desktop.
twitch example api - get stream follows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const getFollowsStream = async ( | |
| userId: number, | |
| accessToken: string, | |
| after: string = "", | |
| follows: any = [] | |
| ) => { | |
| const response = await fetch( | |
| `${TWITCH_URL_API}/streams/followed?user_id=${userId}${ | |
| after ? `&after=${after}` : "" | |
| }`, | |
| { | |
| headers: { | |
| "Client-Id": process.env.NEXT_PUBLIC_CLIENT_ID, | |
| Authorization: "Bearer " + accessToken, | |
| }, | |
| } | |
| ); | |
| const data = await response.json(); | |
| follows = [...follows, ...data.data]; | |
| if (data.pagination && data.pagination.cursor) { | |
| return await getFollowsStream( | |
| userId, | |
| accessToken, | |
| data.pagination.cursor, | |
| follows | |
| ); | |
| } | |
| return follows; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment