Search code examples
youtube-apigoogle-api-python-clientyoutube-data-api

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


I am trying to use the YouTube Data API v3 to get a single video from its YouTube id. I am using the Google API python client. When I try to execute the following code:

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

I always get this error:

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"

But I know there is a id parameter in the API, as it is listed in the reference.

Anybody know what am I doing wrong?


Solution

  • You should use youtube.videos() method.

    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}}