2017-04-11 3 views
-1

Ich habe eine Android-Anwendung erstellt, in der ich nur Profilfotos von Facebook-Benutzer erhalten möchte.Erhalten Sie nur Facebook Profil Fotos mit GraphAPI

Ich habe versucht, Graph API zu verwenden, aber es gibt alle Alben. Gibt es eine Möglichkeit, nur Profilfotos von Nutzern zu finden?

Ich habe versucht, unter Befehl in Graph API:

me/Felder = Fotos {album}

Dank.

+0

https://graph.facebook.com/UID/picture?height=200&width=200, UID die Profil-ID – Janak

+0

@Janak = brauche ich alle Fotos , nicht single –

+0

@saragZala Aktualisieren Sie Ihre Frage, Sie erwähnen dies "Ich möchte nur Profilfotos von Facebook-Nutzer erhalten." – Janak

Antwort

0

schließlich die Lösung von unten Code bekam:

GraphRequest request = GraphRequest.newMeRequest(
      AccessToken.getCurrentAccessToken(), 
      new GraphRequest.GraphJSONObjectCallback() { 
       @Override 
       public void onCompleted(JSONObject object, GraphResponse response) { 
        String id; 
        try { 
         final JSONArray jsonArray = object.getJSONObject("albums").getJSONArray("data"); 
         for (int i = 0; i < jsonArray.length(); i++) { 
          if (jsonArray.getJSONObject(i).getString("name").equals("Profile Pictures")) { 
           id = jsonArray.getJSONObject(i).getString("id"); // ID of Profile Pictures Album 

           new GraphRequest(
             AccessToken.getCurrentAccessToken(), 
             "/" + id + "?fields=photos.limit(6){picture}", 
             null, 
             HttpMethod.GET, 
             new GraphRequest.Callback() { 
              public void onCompleted(GraphResponse response) { 
               try { 
                JSONObject jsonMain = response.getJSONObject(); 
                JSONObject jsonGraphObj = jsonMain.getJSONObject("graphObject"); 
                if (jsonGraphObj.has("photos")) { 
                 if (jsonGraphObj.getJSONObject("photos").has("data")) { 
                  JSONArray jsonArrayData = jsonGraphObj.getJSONObject("photos").getJSONArray("data"); 
                  for (int i = 0; i < jsonArray.length(); i++) { 
                   if (i != 0) { 
                    String url = jsonArrayData.getJSONObject(i).getString("picture"); 
                   } 
                  } 
                 } 
                } 
               } catch (Exception e) { 
                e.printStackTrace(); 
               } 
              } 
             } 
           ).executeAsync(); 
          } 
         } 
        } catch (Exception e) { 
         e.printStackTrace(); 
         DialogsUtils.removeProgressDialog(); 
        } 
       } 
      }); 

    Bundle parameters = new Bundle(); 
    parameters.putString("fields", "albums"); 
    request.setParameters(parameters); 
    request.executeAsync();