google-api-python-client icon indicating copy to clipboard operation
google-api-python-client copied to clipboard

Listing my YouTube playlists = Missing part

Open luc-phan opened this issue 3 years ago • 2 comments

Environment details

  • OS type and version: Windows 10
  • Python version: 3.8.5
  • pip version: 22.2.2
  • google-api-python-client version: 2.63.0

Steps to reproduce

  1. Go to: https://developers.google.com/youtube/v3/docs/playlists/list#try-it
  2. In the mine dropdown, choose: true.
  3. Click on "Execute" to confirm it works.
  4. Click on the "PYTHON" tab to get the code.
  5. Put the code in playlists.py.
  6. Define your application credentials in client_secrets.json.
  7. Change the credentials file name in playlists.py.
  8. pipenv install google-api-python-client.
  9. pipenv install google-auth-oauthlib.
  10. pipenv shell
  11. python playlists.py
  12. Result:
TypeError: Missing required parameter "part"
  1. If you add a "part" argument, it will say:
TypeError: method() takes 1 positional argument but 2 were given

Code example

# -*- coding: utf-8 -*-

# Sample Python code for youtube.playlists.list
# See instructions for running these code samples locally:
# https://developers.google.com/explorer-help/code-samples#python

import os

import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors

scopes = ["https://www.googleapis.com/auth/youtube.readonly"]

def main():
    # Disable OAuthlib's HTTPS verification when running locally.
    # *DO NOT* leave this option enabled in production.
    os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"

    api_service_name = "youtube"
    api_version = "v3"
    client_secrets_file = "client_secrets.json"

    # Get credentials and create an API client
    flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
        client_secrets_file, scopes)
    credentials = flow.run_console()
    youtube = googleapiclient.discovery.build(
        api_service_name, api_version, credentials=credentials)

    request = youtube.playlists().list(
        # "part argument",
        mine=True
    )
    response = request.execute()

    print(response)

if __name__ == "__main__":
    main()

Stack trace

> python .\playlists.py
Please visit this URL to authorize this application: ...
Enter the authorization code: ...
Traceback (most recent call last):
  File ".\playlists.py", line 40, in <module>
    main()
  File ".\playlists.py", line 31, in main
    request = youtube.playlists().list(
  File "C:\Users\...\.virtualenvs\youtube-library-export-f2Qnjj1K\lib\site-packages\googleapiclient\discovery.py", line 1040, in method
    raise TypeError('Missing required parameter "%s"' % name)
TypeError: Missing required parameter "part"
> python .\playlists-with-part-argument.py
Please visit this URL to authorize this application: ...
Enter the authorization code: ...
Traceback (most recent call last):
  File ".\playlists.py", line 40, in <module>
    main()
  File ".\playlists.py", line 31, in main
    request = youtube.playlists().list(
TypeError: method() takes 1 positional argument but 2 were given

luc-phan avatar Sep 30 '22 11:09 luc-phan

Hi there! Is this error still occurring? If so, could you try making the specifying part as the last parameter, like so?:

request = youtube.playlists().list(
        mine=True,
        part="SOMETHING"
    )

vchudnov-g avatar Mar 13 '23 20:03 vchudnov-g

  • Yes, it's still occuring. It's even worse:
    • AttributeError: 'InstalledAppFlow' object has no attribute 'run_console'
    • So I replaced run_console with run_local_server.
  • Yes, if I add part="id", it works.

Thanks.

luc-phan avatar Mar 15 '23 10:03 luc-phan