【发布时间】:2018-05-07 15:26:32
【问题描述】:
我正在尝试通过其 ID 查找 youtube 视频的详细信息(示例 -> yb7E4lQiaZI)。我读到,如果我们只需要详细信息,我们可以使用开发人员控制台中的 api_key。如果我们要进行上传视频等操作,我们需要使用 oauth。我只想和第一个案例一起去。我只需要视频的详细信息,例如我想在列表视图中显示的缩略图 url 和标题。
我正在尝试使用我的 api_key 来执行此操作,但我无法使其工作。最后一行 (system.out.println) 没有打印任何内容。我写的代码如下
try {
YouTube youtube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, new
HttpRequestInitializer() {
public void initialize(HttpRequest request) throws IOException {
}
}).setApplicationName("my_project").build();
HashMap<String, String> parameters = new HashMap<>();
parameters.put("part", "snippet,contentDetails,statistics");
parameters.put("id", "yb7E4lQIaZI");
YouTube.Videos.List videosListByIdRequest = youtube.videos().list(parameters.get("part").toString());
videosListByIdRequest.setKey(MY_API_KEY_FROM_DEVELOPER_CONSOLE);
if (parameters.containsKey("id") && parameters.get("id") != "") {
videosListByIdRequest.setId(parameters.get("id").toString());
}
VideoListResponse response = videosListByIdRequest.execute();
System.out.println(response);
} catch (GoogleJsonResponseException e) {
e.printStackTrace();
System.err.println("There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage());
} catch (Throwable t) {
t.printStackTrace();
}
当我运行调试时,它在“VideoListResponse response = videosListByIdRequest.execute();”行之后退出并且不会转到“System.out.println(response)”行。
应用程序不会崩溃或显示任何错误,它只是不会进入 'system.out.print' 行
【问题讨论】: