Skip to content

Commit 2f9b580

Browse files
committed
fix(channel): 🐛 fix the parameter channel name for get channel and examples
ISSUES CLOSED: sns-sdks#107 sns-sdks#86
1 parent efe4927 commit 2f9b580

4 files changed

Lines changed: 13 additions & 11 deletions

File tree

examples/channel_videos.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
API_KEY = "xxx" # replace this with your api key.
1212

1313

14-
def get_videos(channel_name):
14+
def get_videos(channel_id):
1515
api = pyyoutube.Api(api_key=API_KEY)
16-
channel_res = api.get_channel_info(channel_name=channel_name)
16+
channel_res = api.get_channel_info(channel_id=channel_id)
1717

1818
playlist_id = channel_res.items[0].contentDetails.relatedPlaylists.uploads
1919

@@ -30,8 +30,8 @@ def get_videos(channel_name):
3030

3131

3232
def processor():
33-
channel_name = "googledevelopers"
34-
videos = get_videos(channel_name)
33+
channel_id = "UC_x5XG1OV2P6uZZ5FSM9Ttw"
34+
videos = get_videos(channel_id)
3535

3636
with open("videos.json", "w+") as f:
3737
for video in videos:

examples/subscription.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def get_subscriptions():
2727
"\nCopy the whole url if you finished the step to authorize:\n"
2828
)
2929

30-
api.exchange_code_to_access_token(authorization_response=auth_response)
30+
api.generate_access_token(authorization_response=auth_response)
3131

3232
sub_res = api.get_subscription_by_me(mine=True, parts="id,snippet", count=None)
3333

pyyoutube/api.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def get_channel_info(
479479
self,
480480
*,
481481
channel_id: Optional[Union[str, list, tuple, set]] = None,
482-
channel_name: Optional[str] = None,
482+
for_username: Optional[str] = None,
483483
mine: Optional[bool] = None,
484484
parts: Optional[Union[str, list, tuple, set]] = None,
485485
hl: str = "en_US",
@@ -498,8 +498,10 @@ def get_channel_info(
498498
channel_id ((str,list,tuple,set), optional):
499499
The id or comma-separated id string for youtube channel which you want to get.
500500
You can also pass this with an id list, tuple, set.
501-
channel_name (str, optional):
502-
The name for youtube channel which you want to get.
501+
for_username (str, optional):
502+
The name for YouTube username which you want to get.
503+
Note: This name may the old youtube version's channel's user's username, Not the the channle name.
504+
Refer: https://developers.google.com/youtube/v3/guides/working_with_channel_ids
503505
mine (bool, optional):
504506
If you have give the authorization. Will return your channels.
505507
Must provide the access token.
@@ -520,8 +522,8 @@ def get_channel_info(
520522
"part": enf_parts(resource="channels", value=parts),
521523
"hl": hl,
522524
}
523-
if channel_name is not None:
524-
args["forUsername"] = channel_name
525+
if for_username is not None:
526+
args["forUsername"] = for_username
525527
elif channel_id is not None:
526528
args["id"] = enf_comma_separated("channel_id", channel_id)
527529
elif mine is not None:

tests/apis/test_channels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def testGetChannelInfo(self) -> None:
6363
self.assertEqual(res_by_channel_id.items[0].id, "UC_x5XG1OV2P6uZZ5FSM9Ttw")
6464

6565
res_by_channel_name = self.api.get_channel_info(
66-
channel_name="GoogleDevelopers", return_json=True
66+
for_username="GoogleDevelopers", return_json=True
6767
)
6868
self.assertEqual(
6969
res_by_channel_name["items"][0]["id"], "UC_x5XG1OV2P6uZZ5FSM9Ttw"

0 commit comments

Comments
 (0)