Get photos from facebook album in android

m trying to get all the photos from a percussion album from facebook to android, I use facebook android sdk to complete the task, but the problem is that I don’t know what url request is required to access the photos inside the album?

+3
source share
2 answers

https://graph.facebook.com/ALBUM_ID/photos

If this is for a specific person, then:

https://graph.facebook.com/me/albums/

And then select the album id and then use the first call

EDIT

You will also need to grant permission when creating the Facebook object in the Permission String array, you also need to add user_photos to be able to upload photos

+10
source

The code works for me.

I have two functions: one is to get the album ID, and the other is just to extract all the images from this particular album.

First use the test() function, and then use downloadpic() .

 public void test() { facebook.getAccessToken(); JSONArray albumss=null; String response = null; try { response = facebook.request("me/albums"); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } JSONObject json = null; try { json = Util.parseJson(response); } catch (FacebookError e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } JSONArray albums = null; try { albums = json.getJSONArray("data"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (int i =0; i < albums.length(); i++) { JSONObject album = null; try { album = albums.getJSONObject(i); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { //Here I have selected Profile pic album. if (album.getString("type").equalsIgnoreCase("profile")) { // JSONArray al=null; wallAlbumID = album.getString("id"); // Now you have album id in wallAlbumID(global varible). Log.d("JSON", wallAlbumID); break; } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } 

Now use downloadpic() :

 void downloadpic( ) { facebook.getAccessToken(); String response = null; try { response = facebook.request(wallAlbumID+"/photos"); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } JSONObject json = null; try { json = Util.parseJson(response); } catch (FacebookError e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } JSONArray photos = null; try { photos = json.getJSONArray("data"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (int i =0; i < photos.length(); i++) { JSONObject a = null; try { a = photos.getJSONObject(i); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } String testing = null; try { testing = a.getString("source"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } \ URL value=null; try { value=new URL(testing); //Now you have URL of that particular image use it in your way } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; } } 
+1
source

All Articles