I'm trying to get a list of the videos I've posted in YouTube

When using the explorer:

https://developers.google.com/youtube/v3/docs/search/list

it generated following query

GET https://www.googleapis.com/youtube/v3/search?part=snippet&forMine=true&key={YOUR_API_KEY}

and the following (400) response:

{
 "error": {
  "errors": [
   {
    "domain": "youtube.search",
    "reason": "invalidSearchFilter",
    "message": "Invalid combination of search filters and/or restrictions.",
    "locationType": "parameter",
    "location": ""
   }
  ],
  "code": 400,
  "message": "Invalid combination of search filters and/or restrictions."
 }
}
有帮助吗?

解决方案

This can be done making 2 requests to the Youtube v3 API:

  1. The first request you need to make for this is to get the id of your uploaded videos playlist:

    This is a GET request to url:

    "https://www.googleapis.com/youtube/v3/channels"
    

    with headers:

    "Content-type": "application/json",
    "Authorization": "Bearer %s" % {YOUR ACCESS TOKEN}
    

    and parameters:

    "part": "contentDetails",
    "mine": "true",
    "key": {YOUR APPLICATION KEY}
    

    From the response you want to access:

    response_body["items"][0][contentDetails][relatedPlaylists][uploads]

  2. The second request is to get all the videos you have in your uploads playlist.

    To get this start with a GET request to URL:

    "https://www.googleapis.com/youtube/v3/playlistItems"
    

    sending headers:

    "Content-type": "application/json",
    "Authorization": "Bearer %s" % {YOUR AUTH TOKEN}
    

    and parameters:

    "part": "snippet", {Add other "parts" here like stats if you want that info.}
    "maxResults": {MORE THAN 50? PAGINATION IS NEEDED / SEE BELOW},
    "playlistId": {FROM ABOVE},
    "key": {YOUR API KEY}
    

    The response will have your list of videos and their associated information.

    if (while) the response has response_body["nextPageToken"] in it, you need to resend the request with parameter "pageToken": {NEXT PAGE TOKEN} to get the rest of your paginated results.

其他提示

When setting the forMine parameter, you also have to set the type parameter to video so that the API knows what kinds of resources to return.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top