googleapis / google-api-python-client

🐍 The official Python client library for Google's discovery based APIs.
https://googleapis.github.io/google-api-python-client/docs/
Apache License 2.0
7.78k stars 2.42k forks source link

Listing my YouTube playlists = Missing part #1935

Open luc-phan opened 2 years ago

luc-phan commented 2 years ago

Environment details

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
vchudnov-g commented 1 year ago

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"
    )
luc-phan commented 1 year ago

Thanks.