Youtube search fail with GoogleJsonResponseException: 403 Forbidden

孤街醉人 提交于 2019-12-13 15:24:03

问题


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

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"

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();

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


回答1:


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

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




回答2:


1) You need to get your SHA1 key with "keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android"

2) In API console: Create a client id with this key and full package name.

3) In API console: Create an Android key with this key and full package name.

4) Enable YouTube Data API v3 from console



来源:https://stackoverflow.com/questions/15100916/youtube-search-fail-with-googlejsonresponseexception-403-forbidden

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