Python Youtube API URL

问题描述 投票:0回答:1
import requests
import urllib.parse
API_KEY = API_Key 
USERNAME = 'penguinz0'
before = input("Before: ")
after = input("After: ")
API_KEY = urllib.parse.quote(API_KEY)
USERNAME = urllib.parse.quote(USERNAME)
before = urllib.parse.quote(before)
after = urllib.parse.quote(after)
channel_url = f'https://www.googleapis.com/youtube/v3/channels?key={API_KEY}&forUsername={USERNAME}&part=id'
response = requests.get(channel_url)
channel_id = response.json()['items'][0]['id']
search_url = f'https://www.googleapis.com/youtube/v3/search?key={API_KEY}&channelId={channel_id}&part=snippet,id&order=date&maxResults=20&publishedAfter={after}T00:00:00Z&publishedBefore={before}T23:59:59Z'
response = requests.get(search_url)
videos = response.json()['items']

for video in videos:
    video_title = video['snippet']['title']
    print(video_title)

“所以我想做的是设置用户想要这些设定数量的视频的视频观看次数的日期。我首先手动输入日期并且它们起作用了,但是当我添加变量时它似乎没有起作用拿起任何东西,它只返回括号。”

输入日期:2023-01-01T00:00:00Z 之前 2023-01-01T23:59:59Z 之后。

输出:视频名称:#### 观看次数:####

python api url
1个回答
0
投票

好的,大家,我解决了输入格式错误的问题。我把之前和之后搞混了。所以我在2023年12月5日之后和2023年12月2日之前都是这样做的。这没有意义,应该是相反的,因为 after 是该日期之后的每个视频,而 before 是该日期之前的每个视频,这创建了日期范围。

© www.soinside.com 2019 - 2024. All rights reserved.