android - 在 android 中使用 youtube data api v3 进行 youtube 搜索
问题描述
我正在开发具有此功能的新应用程序:
-用户可以从应用程序中搜索 youtube 视频 ..
我尝试使用 youtube api ..我在 google 控制台中创建了项目,生成了带有 android 应用程序限制的 api_key(编写了应用程序包和 SHA-1证书指纹)。
我使用了这个链接:
https://www.googleapis.com/youtube/v3/search?part=snippet&q=blabla&type=video&key=[api_key]
我来自:https://developers.google.com/youtube/v3 /docs/search/list
但不幸的是我得到了这个回复,我知道为什么
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "ipRefererBlocked",
"message": "The request did not specify any Android package name or signing-certificate fingerprint. Please ensure that the client is sending them or use the API Console to update your key restrictions.",
"extendedHelp": "https://console.developers.google.com/apis/credentials?project=953519755004"
}
],
"code": 403,
"message": "The request did not specify any Android package name or signing-certificate fingerprint. Please ensure that the client is sending them or use the API Console to update your key restrictions."
}
}
我希望任何人都可以拯救我的一天
解决方案
您可能需要设置两个请求标头:
youTube = new YouTube.Builder(new NetHttpTransport(), JacksonFactory.getDefaultInstance(), new HttpRequestInitializer() { @Override public void initialize(HttpRequest request) throws IOException { String packageName = context.getPackageName(); String SHA1 = getSHA1(packageName );
request.getHeaders().set("X-Android-Package", packageName);
request.getHeaders().set("X-Android-Cert",SHA1);
}
}).setApplicationName(appName).build();
推荐阅读
- android - Android Studio 无法启动,原因是 Check Point 防病毒软件将 kotlin-stdlib.jar 移动到隔离区
- javascript - chart.js 折线图每 5 秒更新一次?
- azure - Azure - 集中管理客户端机密
- java - Java ProcessBuilder问题——目录问题
- python - 从 32 升级到 fedora 33 后,dnf 不再工作
- javascript - 正则表达式在第三个斜杠之后但在减号之前获取第一个单词
- flutter - Flutter 自定义包不加载字体和图片 | 扑
- cmake - CMake 无法获取 Python3_SITELIB
- tags - Universal-ctags 可以在输出中生成一个标志,描述标签的种类吗?
- nginx - Nginx 和 uWSGI (13: Permission denied) 同时连接到上游