如何授予我的 youtube api 权限以查看我的私人、草稿、不公开 视频。目前它只能查看公共视频。以及在 python
中更改这些视频和上传视频的权限我尝试了很多东西,也许我是新手,所以我找不到我正在寻求适当的帮助。
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from google.auth.transport.requests import Request
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.errors import HttpError
import datetime
from datetime import timezone, timedelta
import pytz
import google_auth_oauthlib.flow
clientid = 'CLIENT_ID_HERE'
# clientsecret= " CLIENT SECRET HERE "
apikey= 'API KEY HERE'
channelid = 'CHANNEL ID HERE'
# Replace with your own API key
API_KEY = apikey
# Replace with your own channel ID
CHANNEL_ID = channelid
# Authenticate the API client
scopes = ["https://www.googleapis.com/auth/youtube.readonly"]
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
"youtube.json", scopes
)
credentials = flow.run_local_server(port=8080)
youtube = build("youtube", "v3", credentials=credentials)
# Set up the timezone
timezone = pytz.timezone("Asia/Kolkata")
now = datetime.datetime.now(timezone)
# Trying to get list of draft videos on your channel
channel_id = channelid
request = youtube.search().list(
part="id,snippet",
q="channel:" + channel_id + " isDraft",
type="video",
fields="items(id(videoId),snippet(publishedAt,title,description))"
)
response = request.execute()
videos = response["items"]
print(videos)
# Schedule each video on an interval of 15 minutes from the current time
for i, video in enumerate(videos):
video_id = video["id"]["videoId"]
title = video["snippet"]["title"]
description = video["snippet"]["description"]
scheduled_time = now + timedelta(minutes=15 * (i + 1))
iso_time = scheduled_time.isoformat()
# Update the video with the scheduled time
request = youtube.videos().update(
part="snippet,status",
body={
"id": video_id,
"snippet": {
"title": title,
"description": description,
"publishedAt": iso_time,
},
"status": {
"privacyStatus": "private",
"publishAt": iso_time,
"selfDeclaredMadeForKids": False,
},
},
)
response = request.execute()
print(
f"Video '{title}' scheduled for {scheduled_time.strftime('%Y-%m-%d %H:%M:%S')} ({iso_time})")
我得到的输出为空列表