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 –