此代码适用于youtube ...它正在运行,但我需要为facebook提供一个提示或示例:
public class MainActivity extends ActionBarActivity {
ListView videoList;
ArrayList<String> videoArrayList =new ArrayList<String>();
ArrayAdapter<String> videoAdapter;
Context context;
String feedUrl="http://gdata.youtube.com/feeds/api/users/omarsal2002/uploads?v=2&al"
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context=this;
videoList = (ListView) findViewById(R.id.videoList);
videoAdapter = new ArrayAdapter<String>(this, R.layout.video_list_item,
videoArrayList);
videoList.setAdapter(videoAdapter);
VideoListTask loaderTask=new VideoListTask();
loaderTask.execute();
}
public class VideoListTask extends AsyncTask<Void, Void, Void> {
ProgressDialog dialog;
@Override
protected void onPreExecute(){
dialog=new ProgressDialog(context);
dialog.setTitle("Loading Videos");
dialog.show();
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
HttpClient client=new DefaultHttpClient();
HttpGet getRequest=new HttpGet(feedUrl);
try {
HttpResponse responce=client.execute(getRequest);
StatusLine statusline=responce.getStatusLine();
int statusCode=statusline.getStatusCode();
if(statusCode != 200){
return null;
}
InputStream jsonStream=responce.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(jsonStream));
StringBuilder builder=new StringBuilder();
String line;
while((line=reader.readLine())!=null)
{
builder.append(line);
}
String jsonData=builder.toString();
JSONObject json=new JSONObject(jsonData);
JSONObject data=json.getJSONObject("data");
JSONArray items=data.getJSONArray("items");
for(int i=0;i<items.length();i++){
JSONObject video=items.getJSONObject(i);
//String title=video.getString("title");
videoArrayList.add(video.getString("title"));
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result){
dialog.dismiss();
videoAdapter.notifyDataSetChanged();
super.onPostExecute(result);
}
}
}