URL を次のように置き換えます:
http://gdata.youtube.com/feeds/api/videos?author=username&v=2&alt=json同じユーザーのすべての動画を取得できます:
new conn().execute("http://gdata.youtube.com/feeds/api/videos?author=username&v=2&alt=json");
これは conn のクラスです:
class conn extends AsyncTask<String, Integer, String>{
@Override
protected void onPreExecute() {
Log.d("after make conn", "ok");
progress.show();
super.onPreExecute();
}
@Override
protected String doInBackground(String... arg0) {
Log.d("doInBackground", "ok");
String s = GetUrlBody(arg0[0]);
return s;
}
@Override
protected void onPostExecute(String result) {
try{
Log.d("onPostExecute befor parsing", "ok");
/*************************************************************************/
JSONObject jo =(JSONObject) new JSONTokener(result).nextValue();
JSONObject feed = jo.optJSONObject("feed");
JSONArray ent = feed.optJSONArray("entry");
Log.d(" after parsing before loop", "ok");
/*************************************************************************/
for(int i = 0 ; i<ent.length() ; i++){
String title = ent.optJSONObject(i).
optJSONObject("title").optString("$t");
String views = ent.optJSONObject(i).optJSONObject("yt$statistics").optString("viewCount");
String authorName=ent.optJSONObject(i).optJSONArray("author").optJSONObject(0).optJSONObject("name").optString("$t");
String numDisLikes = ent.optJSONObject(i).
optJSONObject("yt$rating").optString("numDislikes");
String numLikes = ent.optJSONObject(i).
optJSONObject("yt$rating").optString("numLikes");
String description = ent.optJSONObject(i).
optJSONObject("media$group").optJSONObject("media$description").optString("$t");
String shortDescribtion=description.substring(0,49);
Log.d(" value of url", description);
String url=ent.optJSONObject(i).optJSONObject("media$group").optJSONArray("media$thumbnail").optJSONObject(0).optString("url");
Log.d(" value of array", url);
String link=ent.optJSONObject(i).optJSONArray("link").optJSONObject(0).optString("href");
Log.d(" after parsing in loop", "ok");
/*************************************************************************/
videoInfo.add("Title:"+title+"\n"+"By:"+authorName+"\n"+shortDescribtion);
Log.d(" after parsing in loop after list", "ok");
db.insertRow(title, numLikes, numDisLikes,views, authorName, link, description, url, vedioName);
Log.d(" after parsing in loop after insert", "ok");
}
Log.d("finish parsing ", "ok");
db.close();
/*************************************************************************/
Listadapter.notifyDataSetChanged();
Log.d(" after notify", "ok");
/*************************************************************************/
}catch(Exception exx) {
Log.getStackTraceString(exx.getCause().getCause());
}
/*************************************************************************/
progress.dismiss();
/*************************************************************************/
super.onPostExecute(result);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
String GetUrlBody (String Url ){
Log.d(" in GetUrlBody", "ok");
HttpClient cli = new DefaultHttpClient();
HttpGet g = new HttpGet(Url);
try{
HttpResponse res = cli.execute(g);
if(res.getStatusLine().getStatusCode() == 200){
String s =EntityUtils.toString(res.getEntity(), HTTP.UTF_8);
return s;
}else {
return "Not Found";
}
}catch(Exception exx){
Log.getStackTraceString(exx.getCause().getCause());
}
return "!";
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}