0
我需要获取Youtube视频的标题,但我似乎无法包装我的头如何将JSONObject从方法和字符串中取出。从JSONObject获取Youtube标题为一个字符串
public static String getTitleQuietly(String youtubeUrl) {
try {
if (youtubeUrl != null) {
URL embededURL = new URL("http://www.youtube.com/oembed?url=" +
youtubeUrl + "&format=json"
);
return new JSONObject(IOUtils.toString(embededURL)).getString("title");
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
我试着这样做:
String x = getTitleQuietly("https://www.youtube.com/watch?v=4fkcTA7YX44");
Toast.makeText(PostingGBDTutorial.this, x, Toast.LENGTH_SHORT).show();
切换字符串参数www.youtube.com/watch?v=4fkcTA7YX44
,甚至视频的最后11个字符:4fkcTA7YX44
,但没有出现。
请参阅https://stackoverflow.com/questions/25228744/how-to-use-oembed-api-using-php-for-youtube –