I'm trying to schedule a video to be published via the YouTube API using the video.update method and the status.publishAt parameter.But I get an error - 400.
The request metadata specifies an invalid scheduled publishing time.
I'm giving the time in the correct format but still getting the error. What can be wrong?I also used the datetime library. And there I formatted the time in ISO format. But the error still occurs.
Has anyone encountered such a problem?
import google_auth_oauthlib.flowimport googleapiclient.discoveryimport googleapiclient.errorsscopes = ["https://www.googleapis.com/auth/youtube.readonly","https://www.googleapis.com/auth/youtube","https://www.googleapis.com/auth/youtube.force-ssl"]api_service_name = "youtube"api_version = "v3"client_secrets_file = 'client_secret.json'flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(client_secrets_file, scopes)credentials = flow.run_local_server(port=0)youtube = googleapiclient.discovery.build(api_service_name, api_version, credentials=credentials)# get upload playlist idrequest = youtube.channels().list( part="contentDetails", mine=True)response = request.execute()uploads = response["items"][0]["contentDetails"]["relatedPlaylists"]["uploads"]# get all uploaded videosrequest = youtube.playlistItems().list( part="snippet,contentDetails,status", playlistId=uploads, maxResults=50,)response = request.execute()allvids = response["items"]while "nextPageToken" in response.keys(): request = youtube.playlistItems().list( part="snippet,contentDetails,status", playlistId=uploads, maxResults=50, pageToken=response["nextPageToken"] ) response = request.execute() allvids += response["items"]# identify only private videosprivvids = [vid for vid in allvids if vid["status"]["privacyStatus"] == "private"]# let's publish the oldest uploaded draftvid = privvids[-1]snippet = vid["snippet"]# modify snippet as needed# note that you must set a categoryId if updating the snippetsnippet["categoryId"] = 27 # this is education# change status to publicstatus = vid["status"]status["privacyStatus"] = "private"status["selfDeclaredMadeForKids"] = Falsestatus["publishAt"] = '2022-12-29T02:00:00.000Z'# apply changesresponse = youtube.videos().update( part='snippet,status', body=dict( snippet=snippet, status=status, id=snippet["resourceId"]["videoId"] )).execute()