4

I think title is self descriptive. In my application I have a log-in form. Based on request, users should be able to set their image of profile via Facebook.

So, my question is, is it possible to show gallery images of users inside application and let users to select an image from it?

I have checked Facebook SDK and goggled as well but those information that I found was base on uploading image to Facebook by Graph.

Any suggestion/comments would be appreciated.

Hesam
  • 52,260
  • 74
  • 224
  • 365

1 Answers1

0

Have you checked this answer here:

ImageView user_picture;
 userpicture=(ImageView)findViewById(R.id.userpicture);
 URL img_value = null;
 img_value = new URL("http://graph.facebook.com/"+id+"/picture?type=large");
 Bitmap mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
 userpicture.setImageBitmap(mIcon1);

You may see this too.

Edit

I think this shall work to load albums, but the only difference is that you need an access token. This means you can fetch the album of the user only if this user is logged into Facebook. The following code has an AsyncTask called getAlbumsData. Within that look into the doInBackground.It fetches JSON and on onPostExecute,you would see it is loading the album into a listview which was already defined earlier.

Here is the (simple) sample code

private class getAlbumsData extends AsyncTask<Void, Void, Void> {

    LinearLayout linlaHeaderProgress = (LinearLayout) findViewById(R.id.linlaHeaderProgress);

    @Override
    protected void onPreExecute() {

        // SHOW THE PROGRESS BAR (SPINNER) WHILE LOADING ALBUMS
        linlaHeaderProgress.setVisibility(View.VISIBLE);
    }

    @Override
    protected Void doInBackground(Void... params) {

        // CHANGE THE LOADING MORE STATUS TO PREVENT DUPLICATE CALLS FOR
        // MORE DATA WHILE LOADING A BATCH
        loadingMore = true;

        // SET THE INITIAL URL TO GET THE FIRST LOT OF ALBUMS
        URL = "https://graph.facebook.com/" + initialUserID
                + "/albums&access_token="
                + Utility.mFacebook.getAccessToken() + "?limit=10";

        try {

            HttpClient hc = new DefaultHttpClient();
            HttpGet get = new HttpGet(URL);
            HttpResponse rp = hc.execute(get);

            if (rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                String queryAlbums = EntityUtils.toString(rp.getEntity());

                JSONObject JOTemp = new JSONObject(queryAlbums);

                JSONArray JAAlbums = JOTemp.getJSONArray("data");

                if (JAAlbums.length() == 0) {
                    stopLoadingData = true;
                    Runnable run = new Runnable() {

                        @Override
                        public void run() {
                            Toast.makeText(getApplicationContext(),
                                    "No more Albums", Toast.LENGTH_SHORT)
                                    .show();
                        }
                    };
                    Albums.this.runOnUiThread(run);

                } else {
                    // PAGING JSONOBJECT
                    if (JOTemp.has("paging"))   {
                        JSONObject JOPaging = JOTemp.getJSONObject("paging");

                        if (JOPaging.has("next")) {
                            String initialpagingURL = JOPaging
                                    .getString("next");

                            String[] parts = initialpagingURL.split("limit=10");
                            String getLimit = parts[1];

                            pagingURL = "https://graph.facebook.com/"
                                    + initialUserID + "/albums&access_token="
                                    + Utility.mFacebook.getAccessToken()
                                    + "?limit=10" + getLimit;

                        } else {
                            stopLoadingData = true;
                            Runnable run = new Runnable() {

                                @Override
                                public void run() {
                                    Toast.makeText(getApplicationContext(),
                                            "No more Albums",
                                            Toast.LENGTH_SHORT).show();
                                }
                            };
                            Albums.this.runOnUiThread(run);
                        }
                    } else {
                        stopLoadingData = true;
                        Runnable run = new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(getApplicationContext(),
                                        "No more Albums",
                                        Toast.LENGTH_SHORT).show();
                            }
                        };
                        Albums.this.runOnUiThread(run);

                    }

                    getAlbums albums;

                    for (int i = 0; i < JAAlbums.length(); i++) {
                        JSONObject JOAlbums = JAAlbums.getJSONObject(i);

                        if (JOAlbums.has("link")) {

                            albums = new getAlbums();

                            // GET THE ALBUM ID
                            if (JOAlbums.has("id")) {
                                albums.setAlbumID(JOAlbums.getString("id"));
                            } else {
                                albums.setAlbumID(null);
                            }

                            // GET THE ALBUM NAME
                            if (JOAlbums.has("name")) {
                                albums.setAlbumName(JOAlbums
                                        .getString("name"));
                            } else {
                                albums.setAlbumName(null);
                            }

                            // GET THE ALBUM COVER PHOTO
                            if (JOAlbums.has("cover_photo")) {
                                albums.setAlbumCover("https://graph.facebook.com/"
                                        + JOAlbums.getString("cover_photo")
                                        + "/picture?type=normal"
                                        + "&access_token="
                                        + Utility.mFacebook
                                                .getAccessToken());
                            } else {
                                albums.setAlbumCover("https://graph.facebook.com/"
                                        + JOAlbums.getString("id")
                                        + "/picture?type=album"
                                        + "&access_token="
                                        + Utility.mFacebook
                                                .getAccessToken());
                            }

                            // GET THE ALBUM'S PHOTO COUNT
                            if (JOAlbums.has("count")) {
                                albums.setAlbumPhotoCount(JOAlbums
                                        .getString("count"));
                            } else {
                                albums.setAlbumPhotoCount("0");
                            }

                            arrAlbums.add(albums);
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {

        // SET THE ADAPTER TO THE LISTVIEW
        lv.setAdapter(adapter);

        // CHANGE THE LOADING MORE STATUS
        loadingMore = false;

        // HIDE THE PROGRESS BAR (SPINNER) AFTER LOADING ALBUMS
        linlaHeaderProgress.setVisibility(View.GONE);
    }

}

For more help, look into the original answer. If still you need more then there's a full working source code with explanation. Though that's a bit more confusing than the answer I referred.

halfer
  • 19,824
  • 17
  • 99
  • 186
Nezam
  • 4,122
  • 3
  • 32
  • 49
  • Thanks Nezam, but my question was how to load Photos (gallery) of Facebook and then let user to select an image from there and not how to load image of profile. Thanks again. – Hesam Mar 06 '13 at 06:45