我正在开发具有此功能的新应用:-用户可以通过该应用搜索YouTube视频。我试图使用youtube api ..i在Google控制台中创建的项目,生成了android_apps限制(编写应用程序包和SHA-1证书指纹)的api_key。我用这个链接: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但不幸的是,我得到了这个回应,并且idk为什么
{
"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 =新的YouTube.Builder(新的NetHttpTransport(),JacksonFactory.getDefaultInstance(),新的HttpRequestInitializer(){@Override公共无效initialize(HttpRequest请求)引发IOException {字符串packageName = context.getPackageName();字符串SHA1 = getSHA1(packageName);
request.getHeaders().set("X-Android-Package", packageName);
request.getHeaders().set("X-Android-Cert",SHA1);
}
})。setApplicationName(appName).build();