Skip to content

Instantly share code, notes, and snippets.

@gNaps
Last active August 25, 2023 10:14
Show Gist options
  • Select an option

  • Save gNaps/f3a9669172cabae89b949ebd3e5c49dd to your computer and use it in GitHub Desktop.

Select an option

Save gNaps/f3a9669172cabae89b949ebd3e5c49dd to your computer and use it in GitHub Desktop.
twitch example api - get stream follows
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