python - 为什么将 youtube api 与 oauth 一起使用时出现授权错误
问题描述
我正在尝试使用 youtube api 在我的帐户中添加创建播放列表。我已经创建了我的 oauth 凭据,我没有更改任何设置同意屏幕的内容。我已经下载了秘密的 json 文件。
从文档中,下面是您创建新播放列表的方法:
# -*- coding: utf-8 -*-
# Sample Python code for youtube.playlists.insert
# See instructions for running these code samples locally:
# https://developers.google.com/explorer-help/guides/code_samples#python
import os
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
scopes = ["https://www.googleapis.com/auth/youtube.force-ssl"]
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 = "YOUR_CLIENT_SECRET_FILE.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().insert(
part="snippet,status",
body={
"snippet": {
"title": "Sample playlist created via API",
"description": "This is a sample playlist description.",
"tags": [
"sample playlist",
"API call"
],
"defaultLanguage": "en"
},
"status": {
"privacyStatus": "private"
}
}
)
response = request.execute()
print(response)
if __name__ == "__main__":
main()
我在没有改变任何东西的情况下运行了它,我就是这样"Please visit this URL to authorize this application"
。
当我单击它时,我得到一个带有以下错误的新选项卡:
Authorization Error
Error 400: invalid_request
Missing required parameter: redirect_uri
有时,执行我得到的完全相同的事情:
Authorization Error
Error 400: invalid_request
Missing required parameter: client_id
错误中提到的缺少的必需参数似乎已填写在授权的 url 中。
任何想法发生了什么?
解决方案
推荐阅读
- reactjs - 如何在更改时更新 React State
- emulation - 加倍位 gb-emu
- python - 层 max_pooling2d 的输入 0 与层不兼容:预期 ndim=4,发现 ndim=5。收到的完整形状:[None, 4, 10, 8, 32]
- amazon-web-services - 在 AWS 上查看我的免费套餐的使用量
- python - malloc():未排序的双链表损坏中止(核心转储)python
- css - Angular:将类添加到跨度选择器
- sql - 选择 MIN MAX 一起改变查询的行为
- python - 将嵌套字典转换为 Pyspark 数据框
- typescript - 打字稿中的依赖类型 - 通过属性名称类型确定类型
- python - 将日期从以多种格式存在的字符串解析为日期时间格式