org.apache.http.client.HttpClient ( apache httpclient)
In order to search more than 50 records I am incrementing start-index
for every search request.
I noticed the results returned are the same irrespective of start-
index
her is the code
public static String getResponse(String startIndex) throws Exception
{
HttpClient httpclient = new DefaultHttpClient();
List<NameValuePair> qparams = new ArrayList<NameValuePair>();
qparams.add(new BasicNameValuePair("q", "telugu movies"));
qparams.add(new BasicNameValuePair("fields",
"entry(media:group(media:title,media:player,yt:duration))"));
qparams.add(new BasicNameValuePair("max-results", "50"));
qparams.add(new BasicNameValuePair("start-index=", startIndex));
URI uri = URIUtils.createURI("http", "gdata.youtube.com", -1, "feeds/
api/videos", URLEncodedUtils.format(qparams, "UTF-8"), null);
HttpGet httpget = new HttpGet(uri);
System.out.println(httpget.getURI());
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
String value=EntityUtils.toString(entity);
System.out.println(value);
return value;//StringUtils.removeStart(value, "<?xml version='1.0'
encoding='UTF-8'?>");
}
public static List<String> getResults(int noOfTimes) throws
Exception{
List<String> results= Lists.newArrayList();
int count=0;
while(count<noOfTimes){
int startIndex=(50*count)+1;
results.add(getResponse(String.valueOf(startIndex)));
count++;
}
return results;
}
if this is not the right way how to search more than 50 records ?
I call the method getResults here I pass number of times to
search , for every search I am calculating start-index as (50*count)
+1;
here the url I am searching
http://gdata.youtube.com/feeds/api/videos?q=telugu+movies&fields=entry%28media%3Agroup%28media%3Atitle%2Cmedia%3Aplayer%2Cyt%3Aduration%29%29&max-results=50&start-index%3D=1
http://gdata.youtube.com/feeds/api/videos?q=telugu+movies&fields=entry%28media%3Agroup%28media%3Atitle%2Cmedia%3Aplayer%2Cyt%3Aduration%29%29&max-results=50&start-index%3D=51
http://gdata.youtube.com/feeds/api/videos?q=telugu+movies&fields=entry%28media%3Agroup%28media%3Atitle%2Cmedia%3Aplayer%2Cyt%3Aduration%29%29&max-results=50&start-index%3D=101
and so....on.
its the same url except for start-index value , is this the right
way to search more than 50?
--
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To post to this group, send email to youtube-api-gdata@googlegroups.com.
To unsubscribe from this group, send email to youtube-api-gdata+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/youtube-api-gdata?hl=en.
No comments:
Post a Comment