Es scheint, dass die Anzahl der Playlist-Einträge von youtube nicht der tatsächlichen Anzahl der Elemente in der Playlist entspricht. Gibt es einen Grund dafür oder mache ich etwas falsch?youtube api-Anzahl stimmt nicht mit der Anzahl der abgerufenen Elemente überein
unten kehrt Mein Code folgendermaßen aus:
there are 1275 videos in the playlist
we retrieved 1274 videos
-Code, in setzen Sie Ihren Schlüssel
import requests
import json
key = '' #Put your key here
upload_playlist_id = 'UUG-Et3jfinzlQql4uEYjAVw'
# Get the video count from the content details of the playlist
params = {
'key' : key,
'id' : upload_playlist_id,
'part' : 'contentDetails'
}
response = requests.get(r'https://www.googleapis.com/youtube/v3/playlists', params)
data = json.loads(response.text)
video_count = data['items'][0]['contentDetails']['itemCount']
print("there are %s videos in the playlist " % (video_count))
# Get the video count from counting all of the items in the playlist
params = {
'key' : key,
'playlistId' : upload_playlist_id,
'maxResults' : 50,
'part' : 'id'
}
response = requests.get(r'https://www.googleapis.com/youtube/v3/playlistItems', params)
data_list = [json.loads(response.text)]
while 'nextPageToken' in data_list[-1]:
params['pageToken'] = data_list[-1]['nextPageToken']
response = requests.get(r'https://www.googleapis.com/youtube/v3/playlistItems', params)
data_list.append(json.loads(response.text))
video_count = sum([len(page_data['items']) for page_data in data_list])
print("we retrieved %s videos" % (video_count))
Ich habe versucht, das Problem ist, dass, wenn Sie die Elemente aus der Wiedergabeliste erhalten - es gibt 1274 Videos. 'itemCount' stimmt nicht mit der tatsächlichen Anzahl überein. – Alter
Was meinst du mit "wenn du die Items von der Playlist bekommst"? Meinst du die YouTube App selbst? nicht die API? – KENdi