google-api-python-client
google-api-python-client copied to clipboard
Listing my YouTube playlists = Missing part
Environment details
- OS type and version: Windows 10
- Python version: 3.8.5
- pip version: 22.2.2
google-api-python-clientversion: 2.63.0
Steps to reproduce
- Go to: https://developers.google.com/youtube/v3/docs/playlists/list#try-it
- In the mine dropdown, choose:
true. - Click on "Execute" to confirm it works.
- Click on the "PYTHON" tab to get the code.
- Put the code in
playlists.py. - Define your application credentials in
client_secrets.json. - Change the credentials file name in
playlists.py. pipenv install google-api-python-client.pipenv install google-auth-oauthlib.pipenv shellpython playlists.py- Result:
TypeError: Missing required parameter "part"
- 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
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"
)
- Yes, it's still occuring. It's even worse:
- AttributeError: 'InstalledAppFlow' object has no attribute 'run_console'
- So I replaced
run_consolewithrun_local_server.
- Yes, if I add
part="id", it works.
Thanks.