我正在构建一个简单的测试Android应用程序,我试图获取有关特定视频的数据。我已经拿到了我的调试密钥库的SHA1指纹,并创建了一个google API密钥(以及我的包名称)。我已经为它启动了YouTube的API服务。Android - youtube api r52 - “访问未配置”
这是我的代码:
YouTube youtube = new YouTube.Builder(new NetHttpTransport(), new GsonFactory(), new HttpRequestInitializer() {
public void initialize(HttpRequest request) throws IOException {}
}).setApplicationName("MyApp").build();
try {
YouTube.Videos.List listVideosRequest = youtube.videos().list("snippet,contentDetails");
listVideosRequest.setId("A3PDXmYoF5U");
listVideosRequest.setKey(GoogleAPIKey.DEBUG_GOOGLE_API_KEY);
VideoListResponse youtubeResponse = listVideosRequest.execute();
List<Video> youtubeVideos = youtubeResponse.getItems();
return youtubeVideos;
} catch (IOException e) {
Log.e("MyApp", e.getLocalizedMessage());
return null;
}
所以,我总是得到一个异常:403,访问未配置。
我用尽了想法,可能是错的。 任何人都已经成功地使用YouTube的API,但与API密钥?
更新:
我只是深深地调试的谷歌图书馆,以便找到,实际的请求是什么样子,也就是发送给Google。它是这样的:
https://www.googleapis.com/youtube/v3/videos?id=A3PDXmYoF5U&key=[my-debug-google-api-key]&part=snippet,contentDetails
与这些头设置:
Accept-Encoding: gzip
User-Agent: MyApp Google-HTTP-Java-Client/1.15.0-rc (gzip)
我看不出有什么不对劲的地方。
您好!你解决了这个问题吗? – Viacheslav
不幸的是,不幸的是:( – ghost23