我正在尝试通过其ID查找youtube视频的详细信息(例如->
yb7E4lQIaZI)。我读到,如果我们只想要详细信息,可以使用开发人员控制台中的api_key。如果我们要执行操作(例如上传视频),则需要使用oauth。我只想和第一种情况一起去。我只需要我想在列表 View 中显示的视频的详细信息,如缩略图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”行
最佳答案
您是否检查了 list 中是否添加了Internet权限。
<uses-permission android:name="android.permission.INTERNET" />
关于android - Android YouTube数据API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47459291/