I am currently running into an issue where I am unable to retrieve a channel resource from the /v3/channels
endpoint using the YouTube API (v3).
The expected behaviour is to get back a channel ID that I am then able to use with the /v3/search
endpoint.
I am using Python and I am attempting to retrieve the resource by username with the forUsername
query parameter.
My code looks like this:
headers = {
"content-type": "application/json",
}
params = {
"part": "snippet,contentDetails,statistics",
"forUsername": "<USERNAME_HERE>",
"key": api_key
}
res = requests.get(channel_endpoint, headers=headers, params=params)
if res.status_code == 200:
data = res.json()
if data["pageInfo"]["totalResults"] == 0:
print("no channel found")
print(data["items"][0]["id"])
# Response:
# {'kind': 'youtube#channelListResponse', 'etag': 'RuuXzTIr0OoDqI4S0RU6n4FqKEM', 'pageInfo': {'totalResults': 0, 'resultsPerPage': 5}}
The odd thing is that I get back a response for certain channels but not all channels.
E.g. "GoogleDevelopers" will return a coherent and meaningful response. Although, my own channel or other external channels do not return a response.
I have already checked API key permissions, restrictions and anything aligned with using the API endpoint/s or keys themselves.
I have already tried to check the username accuracy, channel visibility settings and case sensitivity.
I've gone through multiple routes already and have even considered simply scraping the channelId
from the page source.