개의 주어진 채널 ID의 동영상을 얻으려고했습니다. 하지만 모든 동영상을YouTube API : 주어진 채널의 모든 동영상을 가져 오지 못했습니다.
코드를 받고 있지 않다은 내가 채널의 모든 동영상을 가져 오지하려고 여기
api_key = API_KEY
base_video_url = 'https://www.youtube.com/watch?v='
base_search_url = 'https://www.googleapis.com/youtube/v3/search?'
raw_url = 'https://www.googleapis.com/youtube/v3/' \
'channels?key={}&forUsername={}&part=id'
def getChannelID(username):
''' returns the channel ID '''
r=requests.get(raw_url.format(api_key,username))
json=r.json()
print(json['items'][0]['id'])
return json['items'][0]['id']
def getchannelVideos():
''' returns list of all videos of a given channel '''
chanId=getChannelID('tseries')
first_url = base_search_url + \
'order=date&part=snippet&channelId={}&maxResults=50&key={}'\
.format(chanId,api_key)
video_links = []
url = first_url
while True:
inp = requests.get(url)
resp = inp.json()
for i in resp['items']:
if i['id']['kind'] == "youtube#video":
video_links.append(base_video_url + i['id']['videoId'])
try:
next_page_token = resp['nextPageToken']
url = first_url + '&pageToken={}'.format(next_page_token)
except:
break
print('working') #used this to count repetitions of while loop
return video_links
주어진 채널이 지금까지 11,537 비디오가 T-Series입니다 [click to see the image of the channel showing the count] 그러나 나는 589을 받았습니다 동영상 만
나는이 줄을 사용하여 번호를 계산했습니다. 반복의 루프는 내가 while 루프 (나는 많은 채널에서 시도했지만 같은이 반복됩니다)
(가) 지난 (19 반복) JSON 데이터를 19 번 반복 후에 종료 관찰이에 대한
print('working')
할 것 동안 내가 제공되었다
{'etag': "cbz3lIQ2N25AfwNr-BdxUVxJ_QY/7SEM6nSU4tBD7ZsR5Abt5L-uqAE",
'items': [],
'kind': 'youtube#searchListResponse',
'pageInfo': {'resultsPerPage': 50, 'totalResults': 15008},
'prevPageToken': 'CLYHEAE',
'regionCode': 'IN'}
totalResults가 nextpageID를 제공하지 않는 API는 왜 15008입니까?
AFAIK 채널 객체에 대한 통계를 나열 할 때 videoCount 키 값을 통해 업로드 된 채널의 비디오 카운트가 검색됩니다. 구현시 발생할 수있는 문제 : GET에서 maxResults = 50 – BoboDarph
@BoboDarph 'maxResults = 50'은 API 측에서 구현 된 제한입니다. – Jkdc