获取每张facebook专辑的专辑w.r.t album id - facebook android-sdk

时间:2012-11-26 08:27:10

标签: android facebook photos

我使用facebook android sdk获得了所有的facebook专辑(及其ID),并将其显示在列表中。 现在点击特定列表项目,我想获得该专辑的所有照片(w.r.t“id”)

我这样得到了专辑ID:

if (!facebook.isSessionValid()) {
        facebook.authorize(this, new String[] { "user_photos" },

        new DialogListener() {

            public void onComplete(Bundle values) {

            mAsyncRunner.request("me/albums", new albumsRequestListener()); 
            }

            public void onFacebookError(FacebookError error) {
            }

            public void onError(DialogError e) {
            }

            public void onCancel() {
            }
        });
    }

public class albumsRequestListener implements RequestListener {

    public void onComplete(String response, Object state) {
        // TODO Auto-generated method stub

        try {

            Log.d("Facebook-Example", "Response: " + response.toString());
            JSONObject json = Util.parseJson(response);
            String count = "0";
            JSONArray jArrData = new JSONArray();
            jArrData = json.getJSONArray("data");


            for (int i = 0; i < jArrData.length(); i++) {

                JSONObject objAlbum = jArrData.getJSONObject(i);


                String albumId = objAlbum
                        .getString("id");
                String albumName = objAlbum
                        .getString("name");

                if(objAlbum.has("count"))
                        {
                    count = objAlbum.getString("count");
                        }
                else
                    {
                    count = "0";
                    }

                FbAlbums obj = new FbAlbums();

                obj.setId(albumId);
                obj.setName(albumName);
                obj.setCount(count);


                listFbAlbums.add(obj);
            }


              FB.this.runOnUiThread(new Runnable() {
                    public void run() {
                        adapter = new FbAlbumsListAdapter(
                                getApplicationContext(),listFbAlbums);
                        lvAlmbums.setAdapter(adapter);
                        pb.setVisibility(View.INVISIBLE);

                        lvAlmbums.setOnItemClickListener(new OnItemClickListener() {

                            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                                Toast.makeText(getApplicationContext(), position, Toast.LENGTH_SHORT).show();
                            }


                    });
                    }

                });
        } catch (JSONException e) {
            Log.w("Facebook-Example", "JSON Error in response");
        } catch (FacebookError e) {
            Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
        }
    }

    public void onIOException(IOException e, Object state) {
        // TODO Auto-generated method stub

    }

    public void onFileNotFoundException(FileNotFoundException e,
            Object state) {
        // TODO Auto-generated method stub

    }

    public void onMalformedURLException(MalformedURLException e,
            Object state) {
        // TODO Auto-generated method stub

    }

    public void onFacebookError(FacebookError e, Object state) {
        // TODO Auto-generated method stub

    }

}

如何获得包含每张专辑图片来源的json? 或者还有其他方式吗? 任何帮助将不胜感激, 感谢

1 个答案:

答案 0 :(得分:0)

只需使用相册ID并添加/照片到最后:

mAsyncRunner.request(albumid+"/photos", new photosRequestListener());