I noticed when YouTube allowed for custom playlist thumbnails that the API documentation updated to reflect it. However every time I try, I get errors.
Here is the code I tried
import osimport jsonfrom google_auth_oauthlib.flow import InstalledAppFlowfrom googleapiclient.discovery import buildfrom googleapiclient.http import MediaFileUploadCLIENT_SECRETS_FILE = "client_secrets.json"SCOPES = "https://www.googleapis.com/auth/youtube.force-ssl"REDIRECT_PORT = 9000PLAYLIST_ID = "PLlYdC6fGRAbE0nwjMzm8-v6_52IXr4t9S"THUMBNAIL_PATH = "Darlin2.jpg"def get_authenticated_service(): flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRETS_FILE, SCOPES) credentials = flow.run_local_server(port=REDIRECT_PORT) return build("youtube", "v3", credentials=credentials)def upload_playlist_thumbnail(youtube, playlist_id, thumbnail_path): print("Uploading playlist thumbnail...") media = MediaFileUpload(thumbnail_path, mimetype='image/jpeg') request = youtube.playlistImages().insert( part="snippet", body={"snippet": {"playlistId": playlist_id,"type": "banner" } }, media_body=media ) response = request.execute() print("Thumbnail uploaded successfully.") print(json.dumps(response, indent=2))if __name__ == "__main__": youtube = get_authenticated_service() upload_playlist_thumbnail(youtube, PLAYLIST_ID, THUMBNAIL_PATH)And this is the error I get...
Uploading playlist thumbnail...Traceback (most recent call last): File "c:\Users\lysa.moulton\OneDrive - Concord\Documents\YouTube API\standalone_scripts\playlistthumbupdate.py", line 44, in <module> upload_playlist_thumbnail(youtube, PLAYLIST_ID, THUMBNAIL_PATH) File "c:\Users\lysa.moulton\OneDrive - Concord\Documents\YouTube API\standalone_scripts\playlistthumbupdate.py", line 27, in upload_playlist_thumbnail request = youtube.playlistImages().update( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\lysa.moulton\AppData\Local\Programs\Python\Python311\Lib\site-packages\googleapiclient\discovery.py", line 1048, in method raise TypeError("Got an unexpected keyword argument {}".format(name))TypeError: Got an unexpected keyword argument media_body