2010-09-14 3 views
3

m essayant d'aller chercher toutes les photos de l'album perticular de facebook dans android, j'utilise facebook android sdk pour faire la tâche mais le problème est, je ne sais pas quelle requête url est nécessaire pour accéder les photos à l'intérieur de l'album?chercher des photos de l'album facebook dans android

Répondre

10

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

Si c'est pour une personne alors:

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

Et puis choisissez l'identifiant de l'album et puis utilisez le premier appel

EDIT

Vous devra également donner la permission tout en créant F L'objet acebook dans le tableau de chaînes d'autorisation doit également ajouter user_photos pour pouvoir charger des photos

+1

Eh bien je l'ai essayé https://graph.facebook.com/me/albums/, mais son retour { "data": []} - données vierge bien J'ai un album créé nom "événements" – Hunt

+0

Cela dépend des paramètres de confidentialité de l'album/utilisateur – BeRecursive

+1

Vous avez besoin de la permission user_photos – BeRecursive

1

Code travaillé pour moi.

J'ai deux fonctions - l'une est d'obtenir l'id de l'album et l'autre récupère juste toutes les images de cet album particulier.

Utilisez d'abord la fonction test() puis utilisez 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(); 
     } 
    } 
} 

maintenant utiliser 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; 
     } 
    } 
+2

il renvoie Json: {"data": []} –

+0

Où avez-vous demandé l'autorisation user_photos? C'est important! –

+1

quand u essayez de vous connecter à fb, comme la liste de déclaration déposée permissionNeeds = Arrays.asList ("public_profile", "email", \t \t \t "user_posts", "user_photos", "user_birthday", "user_friends"); et utilisez-le lors de la connexion comme ceci LoginManager.getInstance(). logInWithReadPermissions (this, \t \t \t \t permissionNeeds); –

Questions connexes