我知道如何使用 Android youtube API 使用视频 id 获取图像的缩略图,但是如何使用视频标题查找视频的缩略图?
最佳答案
要解析 YouTube 搜索视频 Json Feed,请使用此链接:
https://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&q=my+love+by+shovon
这里搜索的是“my love by shovon”。
使用任何 json 解析器解析它并获取搜索项目的 YouTube 视频。使用此 Json 解析器。
public JSONObject getJson()
{
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost("https://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&q=my%20love%20by%20shovon");
// Depends on your web service
httppost.setHeader("Content-type", "application/json");
InputStream inputStream = null;
String result = null;
HttpResponse response = null;
try {
response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpEntity entity = response.getEntity();
try {
inputStream = entity.getContent();
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// json is UTF-8 by default i beleive
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
result = sb.toString();
JSONObject job = null;
try {
job = new JSONObject(sb.toString());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return job;
}
关于java - 如何使用 android 版 YouTube API 搜索主题来找到 YouTube 上视频的链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17675378/