Youtube API - no channel name
Asked Answered
G

3

5

I'm trying to retrieve my Youtube channel name using Youtube data API but I'm getting empty item. I have a channel in my Youtube account so it should return one.

These are the query properties I entered -

part:'contentDetails', forUsername: 'Seong+Lee',

to get the following response from their interactive documentation page.

200 OK
- SHOW HEADERS -
{
 "kind": "youtube#channelListResponse",
 "etag": "\"fpJ9onbY0Rl_LqYLG6rOCJ9h9N8/C3QZ-VsykvkpW2zCm7VjGBCayqc\"",
 "pageInfo": {
  "totalResults": 0,
  "resultsPerPage": 5
 },
 "items": [
 ]
}

In my app I get the same response so I figured there is no issue with my request code. Why can't I get the channel name?

Gagnon answered 23/10, 2015 at 3:45 Comment(2)
What's the link to your channel?Tamper
@Tamper youtube.com/channel/UCwy6X3JB24VTsDFqMwdO5JgGagnon
S
5

You can retrieve your contentDetails by using your channel ID.

GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=UCwy6X3JB24VTsDFqMwdO5Jg&key={YOUR_API_KEY}

Your username is apparently not valid.

Shaquana answered 25/10, 2015 at 4:24 Comment(0)
C
4

As it looks like your channel does not have a legacy custom URL, you are not able to use the forUsername parameter. This parameter only works with /user/{channelname} URL's. In this case, it means you have to work with your channel ID which you can find over here.

In order to get the display name of your channel, you need the snippet part instead of the contentDetails.

https://www.googleapis.com/youtube/v3/channels?part=snippet&id=UCwy6X3JB24VTsDFqMwdO5Jg&key={YOUR_API_KEY}

You will then receive display name of the channel as snippet.title

{
    kind: "youtube#channelListResponse",
    etag: ""0KG1mRN7bm3nResDPKHQZpg5-do/L4uU6pmZJ1wQKdGUwnnigYpSEVo"",
    pageInfo: {
        totalResults: 1,
        resultsPerPage: 1
    },
    items: [
    {
        kind: "youtube#channel",
        etag: ""0KG1mRN7bm3nResDPKHQZpg5-do/GKVRHf7CLp-mUGFTR_3wbc5Lq-k"",
        id: "UCwy6X3JB24VTsDFqMwdO5Jg",
        snippet: {
            title: "Seong Lee",

...
Coquet answered 27/10, 2015 at 14:30 Comment(1)
How can I receive the user id UCwy6X3JB24VTsDFqMwdO5Jg, before getting the playlist details?Despot
O
0

If you are authenticate your app using google's oauth2 then you can include the mine parameter and set it to true in your request to recieve your own channel. Check the common use cases here for more info.

See also this answer

Operable answered 10/10, 2020 at 15:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.