2017-04-19 97 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} 

響應有效載荷

{ 
"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

documentation本身所描述的,totalResults是:

整數

結果集中結果的總數。請注意,該值是一個近似值,可能不代表精確值。另外,最大值是1,000,000。

您不應該使用此值創建分頁鏈接。而是使用nextPageTokenprevPageToken屬性值來確定是否顯示分頁鏈接。

該值只是一個近似值/估計值,但不是返回總數items的確切值。我已經使用與您的API相同的詳細信息測試了該API,並且該值趨於從63更改爲6465

說了這麼多,你的代碼沒有錯。這只是預期的行爲。不幸的是,關於totalResults的價值是基於哪裏或哪裏最好使用的地方,沒有說明。最好繼續執行不依賴此參數的實現。

+0

感謝您的回覆,真的很感謝。 –

+0

不客氣。 :) –

相關問題