如何使用其 ID 从 YouTube 获取单个视频?

How to get a single video from YouTube using its id?

我正在尝试使用 YouTube 数据 API v3 从其 YouTube ID 获取单个视频。我正在使用 Google API python 客户端。当我尝试执行以下代码时:

search_response = youtube.search().list(
    id="QkhBcLk_8f0",
    part="snippet",
).execute()

我总是遇到这个错误:

Traceback (most recent call last):
  File "search.py", line 55, in <module>
    youtube_search(args)
  File "search.py", line 24, in youtube_search
    part="snippet",
  File "/usr/local/lib/python2.7/dist-packages/googleapiclient/discovery.py",
line 669, in method
    raise TypeError('Got an unexpected keyword argument "%s"' % name)
TypeError: Got an unexpected keyword argument "id"

但我知道 API 中有一个 id 参数,因为它在 reference 中列出。

有人知道我做错了什么吗?

你应该使用youtube.videos()方法。

youtube.videos().list(id="QkhBcLk_8f0",part="snippet").execute()

{u'etag': u'"YxyobdYztCvdjXOUqpUttvF39GM/nr0_6QcUDyGR0D_Gxz762lsqqfU"',
 u'items': [{u'etag': u'"YxyobdYztCvdjXOUqpUttvF39GM/n7wasYBTHMM3SB4Jtsxu6JeDFPA"',
   u'id': u'QkhBcLk_8f0',
   u'kind': u'youtube#video',
   u'snippet': {u'categoryId': u'27',
    u'channelId': u'UCzu2OUGZlNtXPom3KNPGFzg',
    u'channelTitle': u'FFreeThinker',
    u'description': u'http://facebook.com/ScienceReason ... Great Minds, Great Words: Richard Feynman - The Uncertainty of Knowledge ... The Nature and Purpose of the Universe.\n\nPlaylist "Great Minds, Great Words":\n\u2022 http://www.youtube.com/user/FFreeThinker#grid/user/CC4F721030F8D4D1\n\n---\nPlease SUBSCRIBE to Science & Reason:\n\u2022 http://www.youtube.com/FFreeThinker\n\u2022 http://www.youtube.com/ScienceTV\n\u2022 http://www.youtube.com/Best0fScience\n\u2022 http://www.youtube.com/RationalHumanism\n---\n\nRichard Feynman (1918-1988) was an American  physicist  known for his work in the path integral formulation of quantum mechanics, the theory of quantum electrodynamics and the physics of the superfluidity of supercooled liquid helium, as well as in particle physics (he proposed the parton model).\n\nFor his contributions to the development of quantum electrodynamics, Feynman, jointly with Julian Schwinger and Sin-Itiro Tomonaga, received the Nobel Prize in Physics in 1965. He developed a widely used pictorial representation scheme for the mathematical expressions governing the behavior of subatomic particles, which later became known as Feynman diagrams. During his lifetime, Feynman became one of the best-known scientists in the world.\n\nHe assisted in the development of the atomic bomb and was a member of the panel that investigated the Space Shuttle Challenger disaster. In addition to his work in theoretical physics, Feynman has been credited with pioneering the field of quantum computing, and introducing the concept of nanotechnology (creation of devices at the molecular scale). He held the Richard Chace Tolman professorship in theoretical physics at the California Institute of Technology.\n\nFeynman was a keen popularizer of physics through both books and lectures, notably a 1959 talk on top-down nanotechnology called "There\'s Plenty of Room at the Bottom" and "The Feynman Lectures on Physics". Feynman also became known through his semi-autobiographical books ("Surely You\'re Joking, Mr. Feynman!" and "What Do You Care What Other People Think?") and books written about him, such as "Tuva or Bust!"\n\nHe was regarded as an eccentric and free spirit. He was a prankster, juggler, safecracker, proud amateur painter, and bongo player. He liked to pursue a variety of seemingly unrelated interests, such as art, percussion, Maya hieroglyphs, and lock picking.\n\nFeynman also had a deep interest in biology, and was a friend of the geneticist and microbiologist Esther Lederberg, who developed replica plating and discovered bacteriophage lambda. They had several mutual physicist friends who, after beginning their careers in nuclear research, moved for moral reasons into genetics, among them Le\xf3 Szil\xe1rd, Guido Pontecorvo, and Aaron Novick.\n\n\u2022 http://en.wikipedia.org/wiki/Richard_Feynman\n.',
    u'liveBroadcastContent': u'none',
    u'localized': {u'description': u'http://facebook.com/ScienceReason ... Great Minds, Great Words: Richard Feynman - The Uncertainty of Knowledge ... The Nature and Purpose of the Universe.\n\nPlaylist "Great Minds, Great Words":\n\u2022 http://www.youtube.com/user/FFreeThinker#grid/user/CC4F721030F8D4D1\n\n---\nPlease SUBSCRIBE to Science & Reason:\n\u2022 http://www.youtube.com/FFreeThinker\n\u2022 http://www.youtube.com/ScienceTV\n\u2022 http://www.youtube.com/Best0fScience\n\u2022 http://www.youtube.com/RationalHumanism\n---\n\nRichard Feynman (1918-1988) was an American  physicist  known for his work in the path integral formulation of quantum mechanics, the theory of quantum electrodynamics and the physics of the superfluidity of supercooled liquid helium, as well as in particle physics (he proposed the parton model).\n\nFor his contributions to the development of quantum electrodynamics, Feynman, jointly with Julian Schwinger and Sin-Itiro Tomonaga, received the Nobel Prize in Physics in 1965. He developed a widely used pictorial representation scheme for the mathematical expressions governing the behavior of subatomic particles, which later became known as Feynman diagrams. During his lifetime, Feynman became one of the best-known scientists in the world.\n\nHe assisted in the development of the atomic bomb and was a member of the panel that investigated the Space Shuttle Challenger disaster. In addition to his work in theoretical physics, Feynman has been credited with pioneering the field of quantum computing, and introducing the concept of nanotechnology (creation of devices at the molecular scale). He held the Richard Chace Tolman professorship in theoretical physics at the California Institute of Technology.\n\nFeynman was a keen popularizer of physics through both books and lectures, notably a 1959 talk on top-down nanotechnology called "There\'s Plenty of Room at the Bottom" and "The Feynman Lectures on Physics". Feynman also became known through his semi-autobiographical books ("Surely You\'re Joking, Mr. Feynman!" and "What Do You Care What Other People Think?") and books written about him, such as "Tuva or Bust!"\n\nHe was regarded as an eccentric and free spirit. He was a prankster, juggler, safecracker, proud amateur painter, and bongo player. He liked to pursue a variety of seemingly unrelated interests, such as art, percussion, Maya hieroglyphs, and lock picking.\n\nFeynman also had a deep interest in biology, and was a friend of the geneticist and microbiologist Esther Lederberg, who developed replica plating and discovered bacteriophage lambda. They had several mutual physicist friends who, after beginning their careers in nuclear research, moved for moral reasons into genetics, among them Le\xf3 Szil\xe1rd, Guido Pontecorvo, and Aaron Novick.\n\n\u2022 http://en.wikipedia.org/wiki/Richard_Feynman\n.',
     u'title': u'Great Minds: Richard Feynman - The Uncertainty Of Knowledge'},
    u'publishedAt': u'2010-03-04T15:12:56.000Z',
    u'tags': [u'great',
     u'minds',
     u'words',
     u'richard',
     u'feynman',
     u'uncertainty',
     u'knowledge',
     u'nature',
     u'purpose',
     u'universe',
     u'god',
     u'religion',
     u'atheists',
     u'atheism',
     u'science',
     u'physicists',
     u'quantum',
     u'mechanics',
     u'electrodynamics',
     u'superfluidity',
     u'nobel',
     u'prize',
     u'theoretical',
     u'physics',
     u'atomic',
     u'bomb',
     u'space',
     u'nano',
     u'technology'],
    u'thumbnails': {u'default': {u'height': 90,
      u'url': u'https://i.ytimg.com/vi/QkhBcLk_8f0/default.jpg',
      u'width': 120},
     u'high': {u'height': 360,
      u'url': u'https://i.ytimg.com/vi/QkhBcLk_8f0/hqdefault.jpg',
      u'width': 480},
     u'maxres': {u'height': 720,
      u'url': u'https://i.ytimg.com/vi/QkhBcLk_8f0/maxresdefault.jpg',
      u'width': 1280},
     u'medium': {u'height': 180,
      u'url': u'https://i.ytimg.com/vi/QkhBcLk_8f0/mqdefault.jpg',
      u'width': 320},
     u'standard': {u'height': 480,
      u'url': u'https://i.ytimg.com/vi/QkhBcLk_8f0/sddefault.jpg',
      u'width': 640}},
    u'title': u'Great Minds: Richard Feynman - The Uncertainty Of Knowledge'}}],
 u'kind': u'youtube#videoListResponse',
 u'pageInfo': {u'resultsPerPage': 1, u'totalResults': 1}}