如何制作我的 youtube 频道 youtube 数据 api 的私人视频

问题描述 投票:0回答:0

如何使用 youtube data api python 抓取我的私人或草稿视频。 我编写的代码只允许我获取我的公共视频视频 ID。 我想让它给我我拥有的每个私人视频或草稿视频的视频 ID

这是我的代码

import os
import google.auth
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


channelid = 'CHANNEL_ID_HERE'


# Set up OAuth2 credentials
creds = None
if os.path.exists('token.json'):
    creds = Credentials.from_authorized_user_file('token.json')
if not creds or not creds.valid:
    if creds and creds.expired and creds.refresh_token:
        creds.refresh(Request())
    else:
        flow = InstalledAppFlow.from_client_secrets_file('youtube.json', scopes=['https://www.googleapis.com/auth/youtube.force-ssl'])
        creds = flow.run_local_server(port=0)
    # Save the credentials for the next run
    with open('token.json', 'w') as token_file:
        token_file.write(creds.to_json())
    with open('token.json', 'w') as token_file:
        token_file.write(creds.to_json())

# Set up YouTube API client
youtube = build('youtube', 'v3', credentials=creds)

try:
    # make a request to the API to retrieve a list of videos uploaded by the authenticated user
    response = youtube.videos().list(
        part='id',
        myRating='like',
        maxResults=50  # increase or decrease as needed
    ).execute()

    # extract the video IDs from the response
    video_ids = [item['id'] for item in response['items']]

    print('Video IDs:', video_ids)

except HttpError as error:
    print('An error occurred:', error)
python web-scraping youtube youtube-api
© www.soinside.com 2019 - 2024. All rights reserved.