【PHP】如何使用YouTube API從播放列表中獲取所有視訊?
2020-11-15 PHP
現在我正在使用此連結
http://gdata.youtube.com/feeds/api/playlists/plalistID
從YouTube播放列表中檢索視訊。但問題是隻有25個視訊。但播放列表包含100個視訊。如何從播放列表中獲取所有視訊?
解決辦法
Youtube讓您每個請求最多獲取50個條目。
響應包含一些<link>元素。如果還有更多記錄要提取,則其中之一的格式為<link rel='next' ...,例如
<link
rel='next'
type='application/atom+xml'
href='https://gdata.youtube.com/feeds/api/playlists/plalistID?start-index=26&max-results=25&v=2'
/>
搜尋此元素並檢索href屬性指向的文件,直到響應中沒有
<link rel='next'元素。