Skip to main content
 首页 » 编程设计

python之使用 youtube API v3 时订单不起作用

2025年05月04日21yxwkf

我正在尝试获取某个 channel 的最后 10 个视频。当我运行以下代码时:

from apiclient.discovery import build 
API_SERVICE_NAME = "youtube" 
API_VERSION = "v3" 
 
def youtubeTest(): 
    KEY = "my key here" 
    service = build(API_SERVICE_NAME, API_VERSION , developerKey=KEY)            
    args = {} 
    args['part']='snippet' 
    args['maxResults']='10' 
    args['channelId']='UCq-Fj5jknLsUf-MWSy4_brA' 
    args['order']='date' 
    args['type']='video' 
    results = service.search().list(**args).execute() 
 
    items = results['items'] 
    for item in items: 
        print item['snippet']['publishedAt'] 
 
 
youtubeTest() 

这是我得到的结果

2018-03-13T10:33:45.000Z 
2018-03-07T10:19:59.000Z 
2017-11-22T04:30:00.000Z 
2012-05-06T07:47:37.000Z  
2014-10-08T13:26:35.000Z 
2017-08-10T13:39:17.000Z 
2018-07-28T08:45:00.000Z 
2018-12-26T05:53:46.000Z 
2014-07-11T13:36:08.000Z 
2018-07-12T05:30:09.000Z 

我想要最后十个视频,但这顺序不正确。这段代码在过去几个月一直有效,但我最近遇到了问题。

请您参考如下方法: