python - 使用 urllib 和 json 读取 Python google api
问题描述
我的代码很短,但它不工作,但在 youtube 视频中它工作
import urllib.request
import json
key = "AIzaSyCyTALBjNAEp-Vr5GkilEnLzH0y1Tw6SC4"
data = urllib.request.urlopen("www.googleapis.com/youtube/v3/channels?part=statistics&forUsername=pewdiepie&key="+key).read()
subs = json.loads(data)['items'][0]["statistics"]['subscriberscount']
print(subs)
解决方案
您需要创建自己的 API 密钥
节目
"error": {
"code": 403,
"message": "YouTube Data API v3 has not been used in project 195563281908 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=195563281908 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"errors": [
{
"message": "YouTube Data API v3 has not been used in project 195563281908 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=195563281908 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"domain": "usageLimits",
"reason": "accessNotConfigured",
"extendedHelp": "https://console.developers.google.com"
}
],
"status": "PERMISSION_DENIED"
}
}
在这里您可以找到如何创建自己的 API 密钥: https ://developers.google.com/youtube/v3/getting-started
推荐阅读
- jpeg - Can I create a MJPEG stream from an H.264 I-Frame stream?
- c++ - Parse Json file with country codes with Qt
- python - Django-Edit and update the existing data in database with Form
- c - 找不到 AVRDude 可执行文件。如果 AVRDude 的路径正确,请检查 AVR 首选项
- nsis - NSIS 取消包含错误内容的消息框
- css - Sass 在 Laravel Mix ^4.0.7 中将背景位置值编译为 100%
- apache-kafka - Spring Cloud Bus 事件( RemoteApplicationEvent )未发布到 Kafka
- python - 小部件未在 pyqt5 中显示标签
- python - 为什么我的列表只有一部分写入输出文件?(Python)
- google-apps-script - How can i deploy gmail addon to marketplace?