Skip to content

Commit

Permalink
Replace deprecated users/follows API endpoint with channels/followed
Browse files Browse the repository at this point in the history
  • Loading branch information
buzz committed Sep 9, 2023
1 parent 6d08ac0 commit 020a442
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion twitch_indicator/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def acquire_token(self):
"client_id": TWITCH_CLIENT_ID,
"state": state,
"redirect_uri": TWITCH_AUTH_REDIRECT_URI,
"scope": TWITCH_AUTH_SCOPES,
"scope": " ".join(TWITCH_AUTH_SCOPES),
}
url_parts[4] = urlencode(query)
url = urlunparse(url_parts)
Expand Down
2 changes: 1 addition & 1 deletion twitch_indicator/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
TWITCH_API_URL = "https://api.twitch.tv/helix/"
TWITCH_AUTH_URL = "https://id.twitch.tv/oauth2/authorize"
TWITCH_AUTH_REDIRECT_URI = "twitch-indicator-auth://authorize"
TWITCH_AUTH_SCOPES = "user:read:email"
TWITCH_AUTH_SCOPES = ["user:read:follows"]
TWITCH_CLIENT_ID = "lp42a3ot0vosrva84upd4up077f6vd"
TWITCH_API_LIMIT = 100
DEFAULT_AVATAR = (
Expand Down
9 changes: 5 additions & 4 deletions twitch_indicator/twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def clear_cache(self):

def fetch_followed_channels(self, user_id):
"""Fetch user followed channels and return a list with channel ids."""
url = self.build_url("users/follows", {"from_id": user_id})
loc = "channels/followed"
url = self.build_url(loc, {"user_id": user_id})
resp = self.get_api_response(url)

total = int(resp["total"])
Expand All @@ -42,16 +43,16 @@ def fetch_followed_channels(self, user_id):
last = resp
while fetched < total:
url = self.build_url(
"users/follows",
{"after": last["pagination"]["cursor"], "from_id": user_id},
loc,
{"after": last["pagination"]["cursor"], "user_id": user_id},
)
nxt = self.get_api_response(url)

fetched += len(nxt["data"])
data += nxt["data"]
last = nxt

return [{"id": int(data["to_id"]), "name": data["to_name"]} for data in data]
return [{"id": int(data["broadcaster_id"]), "name": data["broadcaster_name"]} for data in data]

def fetch_live_streams(self, channel_ids):
"""Fetches live streams data from Twitch, and returns as list of
Expand Down

0 comments on commit 020a442

Please sign in to comment.