我知道如何使用 Android youtube API 来获取使用视频 ID 的图像缩略图,但是如何使用视频标题找到视频的缩略图?
问问题
149 次
1 回答
0
要解析 YouTube Searched Video Json Feed,请使用此链接:
https ://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&q=my+love+by+shovon
Here "my love by shovon" is searched item.
使用任何 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;
}
于 2013-07-16T11:43:27.000 回答