Python-Youtube-Api:响应中缺少代码参数

Python-Youtube-Api : Missing code parameter in response

我正在测试 python-youtube 包,使用以下代码:

from pyyoutube import Api

api = Api(
    client_id="yes-my-client-id-here-i-know",
    client_secret="yes-my-client-secret-here-i-know")

authorization_url = api.get_authorization_url()
access_token = api.generate_access_token(authorization_response=authorization_url[0])

print('authorization_url : >>>>>> ', authorization_url)
print('access_token      : >>>>>> ', access_token)

我收到以下错误。

Traceback (most recent call last):
  File "main.py", line 10, in <module>
    access_token = api.generate_access_token(authorization_response=authorization_url[0])
  File "/Users/sleento/production/python-youtube-api/env/lib/python3.8/site-packages/pyyoutube/api.py", line 263, in generate_access_token
    token = oauth_session.fetch_token(
  File "/Users/sleento/production/python-youtube-api/env/lib/python3.8/site-packages/requests_oauthlib/oauth2_session.py", line 244, in fetch_token
    self._client.parse_request_uri_response(
  File "/Users/sleento/production/python-youtube-api/env/lib/python3.8/site-packages/oauthlib/oauth2/rfc6749/clients/web_application.py", line 220, in parse_request_uri_response
    response = parse_authorization_code_response(uri, state=state)
  File "/Users/sleento/production/python-youtube-api/env/lib/python3.8/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 284, in parse_authorization_code_response
    raise MissingCodeError("Missing code parameter in response.")
oauthlib.oauth2.rfc6749.errors.MissingCodeError: (missing_code) Missing code parameter in response.

我解决了,我使用 client_id 而不是 api_key 参数。

from pyyoutube import Api

api = Api(
     api_key="yes-my-APi-key-here-i-know")

authorization_url = api.get_authorization_url()
print('authorization_url : >>>>>> ', authorization_url)