java如何通过使用安卓版youtube API搜索主题来查找youtube上的视频链接? 1 周,3 日 Questions & Answers 149 我知道如何使用Android youtube API使用视频id获取图像的缩略图,但如何使用视频标题找到视频的缩略图
# 1 楼答案 要解析YouTube搜索的视频Json提要,请使用以下链接: 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; }
# 1 楼答案
要解析YouTube搜索的视频Json提要,请使用以下链接:
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解析器