Skip to content

Commit e08fa17

Browse files
authored
Change "follow/unfollow channel" to GQL queries (#102)
Change follow/unfollow to GQL queries, due to discontinued official API endpoints (https://discuss.dev.twitch.tv/t/deprecation-of-create-and-delete-follows-api-endpoints)
1 parent 4ed3c85 commit e08fa17

1 file changed

Lines changed: 34 additions & 9 deletions

File tree

resources/lib/twitch/api/v5/users.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from ... import keys, methods
1414
from ...api.parameters import Boolean, Direction, SortBy
1515
from ...queries import V5Query as Qry
16+
from ...queries import GQLQuery as GQLQry
1617
from ...queries import query
1718

1819

@@ -80,20 +81,44 @@ def check_follows(user_id, channel_id):
8081

8182
# required scope: user_follows_edit
8283
@query
83-
def follow_channel(user_id, channel_id, notifications=Boolean.FALSE):
84-
q = Qry('users/{user_id}/follows/channels/{channel_id}', method=methods.PUT)
85-
q.add_urlkw(keys.USER_ID, user_id)
86-
q.add_urlkw(keys.CHANNEL_ID, channel_id)
87-
q.add_data(keys.NOTIFICATIONS, Boolean.validate(notifications), Boolean.FALSE)
84+
def follow_channel(channel_id, headers={}, notifications=False):
85+
data = [{
86+
"operationName": "FollowButton_FollowUser",
87+
"variables": {
88+
"input": {
89+
"disableNotifications": notifications,
90+
"targetID": str(channel_id)
91+
}
92+
},
93+
"extensions": {
94+
"persistedQuery": {
95+
"version": 1,
96+
"sha256Hash": "14319edb840c1dfce880dc64fa28a1f4eb69d821901e9e96eb9610d2e52b54f2"
97+
}
98+
}
99+
}]
100+
q = GQLQry('', headers=headers, data=data, use_token=False)
88101
return q
89102

90103

91104
# required scope: user_follows_edit
92105
@query
93-
def unfollow_channel(user_id, channel_id):
94-
q = Qry('users/{user_id}/follows/channels/{channel_id}', method=methods.DELETE)
95-
q.add_urlkw(keys.USER_ID, user_id)
96-
q.add_urlkw(keys.CHANNEL_ID, channel_id)
106+
def unfollow_channel(channel_id, headers={}):
107+
data = [{
108+
"operationName": "FollowButton_UnfollowUser",
109+
"variables": {
110+
"input": {
111+
"targetID": str(channel_id)
112+
}
113+
},
114+
"extensions": {
115+
"persistedQuery": {
116+
"version": 1,
117+
"sha256Hash": "29783a1dac24124e02f7295526241a9f1476cd2f5ce1e394f93ea50c253d8628"
118+
}
119+
}
120+
}]
121+
q = GQLQry('', headers=headers, data=data, use_token=False)
97122
return q
98123

99124

0 commit comments

Comments
 (0)