【问题标题】:youtube search using youtube data api v3 in android在 android 中使用 youtube data api v3 进行 youtube 搜索
【发布时间】:2020-02-03 02:45:55
【问题描述】:

我正在开发具有此功能的新应用程序:
- 用户可以从应用中搜索 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."
 }
}

我希望任何人都可以拯救我的一天

【问题讨论】:

  • 检查您是否从link 启用了 youtube 数据 API。另外,请检查您是否拥有有效的 API 密钥。
  • 我启用了 youtube 数据 api 并且我有有效的 api 密钥,因为我将它用于其他用途以确保它是否有效@AmritBhattacharjee

标签: android youtube-data-api android-youtube-api api-key google-console-developer


【解决方案1】:

您可能需要设置两个请求标头:

Youtube API Key

youTube = new YouTube.Builder(new NetHttpTransport(), JacksonFactory.getDefaultInstance(), new HttpRequestInitializer() { @Override 公共无效初始化(HttpRequest 请求)抛出 IOException { String packageName = context.getPackageName(); 字符串 SHA1 = getSHA1(packageName);

    request.getHeaders().set("X-Android-Package", packageName);
    request.getHeaders().set("X-Android-Cert",SHA1);
}

}).setApplicationName(appName).build();

【讨论】:

    猜你喜欢
    • 2014-10-23
    • 1970-01-01
    • 2020-01-21
    • 2020-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-01
    • 2016-07-13
    相关资源
    最近更新 更多