Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hi Thanks all you guys for pointing me the way I want to fallow. I had come up with something finally and also like to share my expirance </p> <p>According to the youtube we can request data as xml or json. I used json method for my implementation </p> <p><a href="http://gdata.youtube.com/feeds/api/videos?q=title_you_want_to_search&amp;max-results=1&amp;v=2&amp;alt=jsonc" rel="nofollow">http://gdata.youtube.com/feeds/api/videos?q=title_you_want_to_search&amp;max-results=1&amp;v=2&amp;alt=jsonc</a></p> <p>you can get more information from <a href="https://developers.google.com/youtube/2.0/developers_guide_jsonc" rel="nofollow">youtube developer guide</a> </p> <p>above request "title_you_want_to_search" is the keyword you want to search. and we can customize the result by passing the extra parameters to the url. </p> <ul> <li>"max-results" : mention how many results you want to get (In my case I just want only one) </li> <li>"alt" : the format you want results Json or xml</li> </ul> <p>First we need to request data from Youtube api and then we have to select which part of information we want to choose from array. In my case I used the "data" and "items" to get the videoid. after we tacking the videoId then we can make the video URL like this </p> <p><code>String mVideoLink = "https://youtu.be/"+videoID;</code> (I used following functions to get this thing done)</p> <pre><code>public String readYoutubeFeed(String songTitle) { StringBuilder builder = new StringBuilder(); HttpClient client = new DefaultHttpClient(); String url = "http://gdata.youtube.com/feeds/api/videos?q="+songTitle+"&amp;max-results=1&amp;v=2&amp;alt=jsonc"; try { URLEncoder.encode(url, "UTF-8"); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); Log.v(TAG,"encode error"); } HttpGet httpGet = new HttpGet(url); try { HttpResponse response = client.execute(httpGet); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { HttpEntity entity = response.getEntity(); InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content, "UTF-8")); String line; while ((line = reader.readLine()) != null) { builder.append(line); } } else { Log.v(TAG,"Failed to download file"); } } catch (ClientProtocolException e) { e.printStackTrace(); Log.v(TAG,"readYoutubeFeed exeption1"); } catch (IOException e) { e.printStackTrace(); Log.v(TAG,"readYoutubeFeed exeption2"); } return builder.toString(); } public String getYouTubeVideoId(String songTitle){ String jesonData = readYoutubeFeed(songTitle); Log.i(TAG,jesonData); String title = "123"; try { SONObject jObj = new JSONObject(jesonData); JSONArray ja = jObj.getJSONObject("data").getJSONArray("items"); JSONObject jo = (JSONObject) ja.get(0); title = jo.getString("id"); Log.v(TAG,"id is " +title); } catch (Exception e) { e.printStackTrace(); Log.v(TAG,"error occerd"); } return title; </code></pre> <p>}</p> <p>One important thing want to mention in this converting strings to "UTF-8" is want to do because creating JsonArray may be throw exceptions. May be there are better ways to do this. If there any suggest</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload