1

I am trying to get a list of channel id a user have made using YouTube Data API (V3). How do I do this? I have user access token obtained after authorisation.

I want to fetch subscriber count for each channel which I have already done by passing one of the ID I know for a channel but that is for testing purposes.

I am using RestTemplate from org.springframework.web.client to make the request.

RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();

//what parameters to set?

URIBuilder uriBuilder = URIBuilder.fromUri("https://www.googleapis.com/youtube/v3/channels");

I tried implementing a solution, as suggested by this SO answer but wasn't even able to make a good request.

Community
  • 1
  • 1
Shubham A.
  • 2,446
  • 4
  • 36
  • 68

2 Answers2

0

It looks like you already have the right approach, using https://www.googleapis.com/youtube/v3/channels. If you just want to get channel IDs for the authenticated user, you can use the parameters part=id and mine=true.

To use the access token, you can follow one of the approaches here - either include Authorization: Bearer ACCESS_TOKEN in the HTTP request header, or as another query parameter access_token=ACCESS_TOKEN.

Example request:

https://www.googleapis.com/youtube/v3/channels?
    part=id&
    mine=true&
    access_token=ACCESS_TOKEN

Example response, with channel IDs in the items/id field:

{
 "kind": "youtube#channelListResponse",
 "etag": ETAG,
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#channel",
   "etag": ETAG,
   "id": "UCBR8-60-B28hp2BmDPdntcQ"
  }
 ]
}

I don't have much guidance on how to make these requests using the Spring framework - if you're still having trouble, I recommend verifying that they work outside of Spring. You can find more info on the channels#list page, and to test generating and using OAuth access tokens try the OAuth 2.0 Playground.

Tyler C.
  • 643
  • 6
  • 10
0

If you are receiving an Error 400:

BAD REQUEST

  • incompatibleParameters - The request specifies two or more parameters that cannot be used in the same request.
  • invalidFilters - The request specifies an invalid filter parameter.
  • invalidPageToken - The request specifies an invalid page token.
  • *8missingRequiredParameter** - The request is missing a required parameter.
  • unexpectedParameter - The request specifies an unexpected parameter.

Check the Bad Request error description you are receiving to compare and change it with the sample codes and API Reference guide to follow the correct format.

Try using Java Code Samples to familiarize yourself with Youtube Data API.

Sources:

https://developers.google.com/youtube/v3/code_samples/

https://developers.google.com/api-client-library/java/

https://github.com/youtube/api-samples

https://youtu.be/HTr778JctJE?list=PLhBgTdAWkxeD0Kpo-Qtzv1Gc7UhPRrPgn

Mr.Rebot
  • 6,703
  • 2
  • 16
  • 91