kishidp
kishidp

Reputation: 1948

How to fetch url for photo from Facebook Graph API (/me/photos)

Using Facebook Graph API, I can query the list of photos uploaded by user (/me/photos/?type=uploaded)

However, this only returns a list of ids. I assume this list is the id for the photo, but how can I use this id to fetch the url?

Upvotes: 1

Views: 234

Answers (3)

Reuben Thompson
Reuben Thompson

Reputation: 350

You need to add the link field to the request - eg ask for /me/photos?fields=link&type=uploaded

Upvotes: 2

Shoeb Siddique
Shoeb Siddique

Reputation: 2825

Please create a URL like this-

https://graph.facebook.com/USER_FB_ID/picture?type=large
  • REPLACE USER_FB_ID with fb id which you are receiving onSuccess

EDIT

Working code to fetch the list of photos with source URL .

                                            System.out.println("Logged in with fb");
                                            Bundle params = new Bundle();
                                            _accesToken = _sPrefsFB.getString("access_token", "");
                                            System.out.println("_accesToken Bundle : " + _accessToken);

                                            params.putString("access_token", _accessToken);


                                            _imagesList.clear();
                                            mAsyncRunner.request("/me/albums" ,params,"GET", new RequestListener() {
                                                @Override
                                                public void onComplete(String response, Object state) {
                                                    //                      Log.d("Photos Album ", response);

                                                    //need to set album adapter

                                                    if (response!=null&&!response.equalsIgnoreCase("")) {
                                                        //                          System.out.println("Response of fb album : " +response);
                                                        try {
                                                            JSONObject _jObjectMain  = new JSONObject(response);
                                                            JSONArray _jArrayMain = _jObjectMain.getJSONArray("data");
                                                            System.out.println("Size of Album list fb : " + _jArrayMain.length());

                                                            if (_jArrayMain.length()>0) {
                                                                _albumListFB.clear();
                                                                for (int i = 0; i < _jArrayMain.length(); i++) {
                                                                    JSONObject _jObjectSub  = _jArrayMain.getJSONObject(i);
                                                                    FaceBookAlbumBean _bean = new FaceBookAlbumBean();
                                                                    if (_jObjectSub.has("id")) {
                                                                        String _albumID =  _jObjectSub.getString("id"); 
                                                                        _bean.set_albumID(_albumID);
                                                                    }
                                                                    if (_jObjectSub.has("name")) {
                                                                        String _albumName = _jObjectSub.getString("name");
                                                                        _bean.set_albumName(_albumName);
                                                                    }

                                                                    _albumListFB.add(_bean);

                                                                }

                                                                //need to call fb images ws

                                                                Bundle params = new Bundle();
                                                                _accesToken = _sPrefsFB.getString("access_token", "");
                                                                System.out.println("_accesToken Bundle : " + _accessToken);
                                                                params.putString("access_token", _accessToken);
                                                                for (int i = 0; i < _albumListFB.size(); i++) {
                                                                    String _albumID = _albumListFB.get(i).get_albumID();

                                                                    mAsyncRunner.request("/"+_albumID+"/photos" ,params,"GET", new RequestListener() {
                                                                        @Override
                                                                        public void onComplete(String response, Object state) {
                                                                            Log.d("PHotos from album", response);
                                                                            if (response!=null&&!response.equalsIgnoreCase("")) {
                                                                                try {
                                                                                    JSONObject _jObjectMain = new JSONObject(response);
                                                                                    if (_jObjectMain.has("data")) {
                                                                                        JSONArray _jArrayMain = _jObjectMain.getJSONArray("data");
                                                                                        if (_jArrayMain.length()>0) {

                                                                                            for (int i = 0; i < _jArrayMain.length(); i++) {
                                                                                                JSONObject _jObjectSub = _jArrayMain.getJSONObject(i);
                                                                                                CameraRollBean _bean  = new CameraRollBean();
                                                                                                if (_jObjectSub.has("images")) {
                                                                                                    JSONArray _jArraySub = _jObjectSub.getJSONArray("images");
                                                                                                    if (_jArraySub.length()>0) {
                                                                                                        System.out
                                                                                                        .println("Image Array length : " + _jArraySub.length()) ;
                                                                                                        JSONObject _jObjectSub1 = _jArraySub.getJSONObject(_jArraySub.length()-1);
                                                                                                        if (_jObjectSub1.has("source")) {

                                                                                                            String  _source = _jObjectSub1.getString("source");
                                                                                                            /*System.out
                                                                                                                .println("Source Image : "  +_source);*/
                                                                                                            _bean.setFilePath(_source);
                                                                                                        }
                                                                                                    }
                                                                                                }
                                                                                                _imagesList.add(_bean);
                                                                                            }
                                                                                        }




                                                                                    }
                                                                                } catch (JSONException e) {
                                                                                    // TODO Auto-generated catch block
                                                                                    e.printStackTrace();
                                                                                }
                                                                            }
                                                                            System.out.println("_imagesList Size : " +_imagesList.size());

                                                                        }

                                                                        @Override
                                                                        public void onIOException(IOException e, Object state) {
                                                                        }

                                                                        @Override
                                                                        public void onFileNotFoundException(FileNotFoundException e,
                                                                                Object state) {
                                                                        }

                                                                        @Override
                                                                        public void onMalformedURLException(MalformedURLException e,
                                                                                Object state) {
                                                                        }

                                                                        @Override
                                                                        public void onFacebookError(FacebookError e, Object state) {
                                                                        }
                                                                    },null);
                                                                }





                                                            }
                                                        } catch (JSONException e) {
                                                            // TODO Auto-generated catch block
                                                            e.printStackTrace();
                                                        } 
                                                    }



                                                }

                                                @Override
                                                public void onIOException(IOException e, Object state) {
                                                }

                                                @Override
                                                public void onFileNotFoundException(FileNotFoundException e,
                                                        Object state) {
                                                }

                                                @Override
                                                public void onMalformedURLException(MalformedURLException e,
                                                        Object state) {
                                                }

                                                @Override
                                                public void onFacebookError(FacebookError e, Object state) {
                                                }
                                            },null);
                                            //          }

Upvotes: 0

Parsania Hardik
Parsania Hardik

Reputation: 4623

Try using this link: https://graph.facebook.com/ fbid /picture?type=large

Upvotes: 0

Related Questions