YouTube搜索失败,并显示GoogleJsonResponseException:禁止使用403 [英] Youtube search fail with GoogleJsonResponseException: 403 Forbidden

查看:195
本文介绍了YouTube搜索失败,并显示GoogleJsonResponseException:禁止使用403的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个基本过程,但我不知道出了什么问题.

This seems like a basic procedure but I don't know what's going wrong.

logcat输出错误:

Error in logcat output:

com.google.api.client.googleapis.json.GoogleJsonResponseException:
403 Forbidden
{
"code" : 403, 02-26
"errors" : [ {
"domain" : "usageLimits",
"message" : "Access Not Configured",
"reason" : "accessNotConfigured"
}
"message" : "Access Not Configured"

我在code.google.com API控制台中配置了YouTube数据API,并获得了适用于我的Android应用的简单访问API密钥.

I configured in the code.google.com API console the YouTube data API and got a simple access API key for my Android app.

代码在下面;与用于搜索的示例代码相同:

The code is below; the same as the sample code for search:

YouTube youTube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY,
  new HttpRequestInitializer() {
    @Override
    public void initialize(HttpRequest httpRequest) throws IOException {}
})
.setApplicationName("youtubeplayer")
.setYouTubeRequestInitializer(new YouTubeRequestInitializer(DEV_KEY))
.build();

YouTube.Search.List search = youTube.search().list("id,snippet");
//search.setKey(DEV_KEY);
search.setQ(videoName);
search.setType("video");

search.setFields("items(id/kind,id/videoId,snippet/title,snippet/thumbnails/default/url)");
search.setMaxResults(NUMBER_OF_VIDEO);
SearchListResponse searchListResponse = search.execute();
List<SearchResult> searchResultList = searchListResponse.getItems();

这是针对Android的.我可以使用同一键通过YouTube Android播放器API播放视频.

This is for Android. I can play videos with the YouTube Android player API, using the same key.

推荐答案

您需要使用浏览器密钥来访问Youtube Data API. Android密钥仅用于Youtube Player.

You need to use the Browser Key for accessing Youtube Data API. Android key is used only for Youtube Player.

因此,只需在DevConsole中生成Browser键,就可以了.

So just generate the Browser key in the DevConsole and you are good to go.

这篇关于YouTube搜索失败,并显示GoogleJsonResponseException:禁止使用403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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