YouTube API key gives 500 error when restricted to Android

主宰稳场 提交于 2019-12-02 13:48:28

问题


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"
    }
}

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'

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?


回答1:


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.



来源:https://stackoverflow.com/questions/49764365/youtube-api-key-gives-500-error-when-restricted-to-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!