facebook通过Android应用程序提供

时间:2014-03-20 20:54:06

标签: php android json facebook

我试图创建一个Android应用程序可以获取页面提要和照片...我需要一个例子...我试试这个json代码:  String feedUrl =“http://www.facebook.com/feeds/page.php?id=1374787696103514&format=json&start-index=1&max-results=10”; 但我不知道如何使用它....顺便说一下我对android的新方式...... 谢谢你的帮助!!

此代码适用于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);
        }

    }
}

0 个答案:

没有答案