仅限于Android时,YouTube API密钥会显示500错误 [英] YouTube API key gives 500 error when restricted to Android

查看:88
本文介绍了仅限于Android时,YouTube API密钥会显示500错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难使用安全地用于Android的密钥查询YouTube搜索API.看来,当我从此密钥中删除限制时,请求可以正常工作.当我尝试将其锁定并按照

I am having a very difficult time querying the YouTube search API using a key that is secured for use on Android exclusively. It seems when I remove restrictions from this key, the request works fine. When I attempt to lock it down and send the cert and package headers as described in this solution, I receive a very unhelpful 500 error:

{
    "error": {
        "errors": [
            {
                "domain": "global",
                "reason": "internalError",
                "message": "Internal Error"
            }
        ],
        "code": 500,
        "message": "Internal Error"
    }
}

这是我正在尝试使用cURL格式的请求,其中删除了私人信息:

Here is the request I'm attempting in cURL form, with private information redacted:

curl -X GET \
  'https://www.googleapis.com/youtube/v3/search/?q=songs&maxResults=25&key=my_api_key&part=snippet' \
  -H 'x-android-cert: xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx' \
  -H 'x-android-package: com.xx.xx'

该API的文档表示仅在StackOverflow上提供此支持.有没有Google工程师可以帮助我理解为什么失败了?

The documentation for this API indicates that support is only available here on StackOverflow. Are there any Google engineers that can help me understand why this is failing?

推荐答案

经过反复试验,这似乎是由 x-android-cert 标头中发送的指纹格式引起的.与其接受开发者控制台要求的相同格式( AB:CD:EF:01:23:... ),它需要以小写的十六进制字符串( abcdef0123)发送... ).希望这可以帮助不幸的下一个灵魂陷入困境.

After some trial and error, this appears to be caused by the format of the fingerprint sent in the x-android-cert header. Instead of accepting the same format required by the dev console (AB:CD:EF:01:23:...), it needs to be sent as a lowercased hex string (abcdef0123...). Hopefully this helps out the next soul unfortunate enough to run into this.

这篇关于仅限于Android时,YouTube API密钥会显示500错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆