2017-04-19 2 views
2

YouTube v3 검색 API를 사용하고 있습니다. "totalResults"개수와 response.items 필드에 반환 된 항목 목록이 일치하지 않습니다. 요청에 50 개의 동영상을 요청하고 있습니다. 리턴 된 응답은 totalResults를 65로 계산하지만 응답 페이로드에는 3 개의 비디오 만 있습니다. 누군가이 문제를 디버그하도록 도와 줄 수 있습니까?TotalResults 수는 YouTube v3 검색 API에서 반환 된 실제 결과와 일치합니다.

API : www.googleapis.com/youtube/v3/search/list

요청 페이로드

{key=AIzaSyDXXQAtfbLwl6ZVoDDJPeeHKiWz3SzfOmM, maxResults=50, order=date, part=snippet, publishedAfter=2017-03-20T23:59:59.999-04:00, publishedBefore=2017-04-19T23:59:59.001-04:00, q=(("Wood Mackenzie" OR "Wood Mac" OR Woodmac OR @woodmackenzie) AND NOT (fleetwood OR "fleet wood" OR 9WoodMac)) , type=video} 

응답 페이로드

documentation 자체 같이
{ 
"kind": "youtube#searchListResponse", 
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/HTW4WQODZeERIv51VrRfOhir8dg\"", 
"nextPageToken": "CDIQAA", 
"regionCode": "US", 
"pageInfo": { 
    "totalResults": 65, 
    "resultsPerPage": 50 
}, 
"items": [ 
    { 
    "kind": "youtube#searchResult", 
    "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/lnNNrToZHGTehIEJ6bvEx5RZMo4\"", 
    "id": { 
    "kind": "youtube#video", 
    "videoId": "obzlB21t904" 
    }, 
    "snippet": { 
    "publishedAt": "2017-04-14T11:38:08.000Z", 
    "channelId": "UC60Sa1LQjgy_a-K8ThN4eQw", 
    "title": "Fleet wood mac Live at Leeds", 
    "description": "", 
    "thumbnails": { 
    "default": { 
     "url": "https://i.ytimg.com/vi/obzlB21t904/default.jpg", 
     "width": 120, 
     "height": 90 
    }, 
    "medium": { 
     "url": "https://i.ytimg.com/vi/obzlB21t904/mqdefault.jpg", 
     "width": 320, 
     "height": 180 
    }, 
    "high": { 
     "url": "https://i.ytimg.com/vi/obzlB21t904/hqdefault.jpg", 
     "width": 480, 
     "height": 360 
    } 
    }, 
    "channelTitle": "KEVIN MARSHALL", 
    "liveBroadcastContent": "none" 
    } 
    }, 
    { 
    "kind": "youtube#searchResult", 
    "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/uYuuTAL3vtnFI1WOYjth0cso2Xo\"", 
    "id": { 
    "kind": "youtube#video", 
    "videoId": "gHAn0SbwKMg" 
    }, 
    "snippet": { 
    "publishedAt": "2017-04-06T22:17:31.000Z", 
    "channelId": "UC3_MxBSSbmGznoSTgoBQ7_w", 
    "title": "Beat Club: British Invasion 60's, Pt-2; Animals-Move-Fleet Wood Mac-J.Mayall-Who-Pacemakers-Kinks", 
    "description": "Eric Burdon & Animals: C.C. Rider 0:01 The Move: Wild Tiger Woman 3:55 Fleet Wood Mac: Dragonfly 6:26 John Mayall: My Pretty Girl 9:47 Thunderclap ...", 
    "thumbnails": { 
    "default": { 
     "url": "https://i.ytimg.com/vi/gHAn0SbwKMg/default.jpg", 
     "width": 120, 
     "height": 90 
    }, 
    "medium": { 
     "url": "https://i.ytimg.com/vi/gHAn0SbwKMg/mqdefault.jpg", 
     "width": 320, 
     "height": 180 
    }, 
    "high": { 
     "url": "https://i.ytimg.com/vi/gHAn0SbwKMg/hqdefault.jpg", 
     "width": 480, 
     "height": 360 
    } 
    }, 
    "channelTitle": "ROCK&POPS1_koba", 
    "liveBroadcastContent": "none" 
    } 
    }, 
    { 
    "kind": "youtube#searchResult", 
    "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/tapelxOG4Q3gZRJCR2qaVdt-ZO8\"", 
    "id": { 
    "kind": "youtube#video", 
    "videoId": "5GvLbFBdcF4" 
    }, 
    "snippet": { 
    "publishedAt": "2017-04-02T04:48:47.000Z", 
    "channelId": "UC6fn383TI1HVDYW4dSEIogQ", 
    "title": "\"Dreams\" by fleet wood mac (vocal cover)", 
    "description": "I do not own this song. I do not make a profit off of this song. It belongs to the person(s) who wrote it. Please subscribe and comment below any suggestions?!", 
    "thumbnails": { 
    "default": { 
     "url": "https://i.ytimg.com/vi/5GvLbFBdcF4/default.jpg", 
     "width": 120, 
     "height": 90 
    }, 
    "medium": { 
     "url": "https://i.ytimg.com/vi/5GvLbFBdcF4/mqdefault.jpg", 
     "width": 320, 
     "height": 180 
    }, 
    "high": { 
     "url": "https://i.ytimg.com/vi/5GvLbFBdcF4/hqdefault.jpg", 
     "width": 480, 
     "height": 360 
    } 
    }, 
    "channelTitle": "Musikallitee", 
    "liveBroadcastContent": "none" 
    } 
    } 
] 
} 

답변

2

totalResults is :

정수

결과 집합의 결과 총 개수입니다. 값은 근사치이며 정확한 값을 나타내지 않을 수 있습니다. 또한 최대 값은 1,000,000입니다.

페이지 매김 링크를 만들 때는이 값을 사용하지 마십시오. 대신 nextPageTokenprevPageToken 속성 값을 사용하여 페이지 매김 링크를 표시할지 여부를 결정하십시오.

이 값은 근사치/추정치이지만, items의 총 수에 대한 정확한 값은 반환되지 않습니다. 귀하의 것과 동일한 세부 사항으로 API를 테스트했으며 값은 63에서 6465으로 변경되는 경향이 있습니다.

이렇게 말하면 코드에는 아무런 이상이 없습니다. 예상 한 행동 일뿐입니다. 불행히도, totalResults의 값이 어디에 사용되는지 또는 어디에 가장 잘 사용되는지는 어디에도 명시되어 있지 않습니다. 이 매개 변수에 의존하지 않는 구현을 진행하는 것이 가장 좋습니다.

+0

답장을 보내 주셔서 감사합니다. 정말로 감사드립니다. –

+0

당신을 진심으로 환영합니다. :) –