2015-12-22 4 views
1

Я хотел бы получить целые фотографии пользователей из Facebook с помощью последней версии SDK для создания, как и в галерее с использованием facebook images.i, попробовал код ниже от here и не смог сделать его. Не получаю никаких данных с fb.can кто-нибудь покажет мне, какой образец учебника относится к этому или помогает это сделать?Извлечь альбомы пользователей с помощью последней версии SDK на facebook?

/* make the API call */ 
new GraphRequest(
    AccessToken.getCurrentAccessToken(), 
    "/{user-id}/albums", 
    null, 
    HttpMethod.GET, 
    new GraphRequest.Callback() { 
     public void onCompleted(GraphResponse response) { 
      /* handle the result */ 
     } 
    } 
).executeAsync(); 
+0

привет, это мой ответ ios ... вам может помочь ... если у вас есть какие-либо вопросы, тогда я вам поможем http://stackoverflow.com/questions/30207465/ios-how-to- get-facebook-album-photos-picker/31789234 # 31789234 –

ответ

2

Попробуйте этот код ..

private ArrayList<FacebookAlbum> alFBAlbum = new ArrayList<>(); 
/*make API call*/ 
    new GraphRequest(
        AccessToken.getCurrentAccessToken(), //your fb AccessToken 
        "/" + AccessToken.getCurrentAccessToken().getUserId() + "/albums",//user id of login user 
        null, 
        HttpMethod.GET, 
        new GraphRequest.Callback() { 
         public void onCompleted(GraphResponse response) { 
          Log.d("TAG", "Facebook Albums: " + response.toString()); 
          try { 
           if (response.getError() == null) { 
            JSONObject joMain = response.getJSONObject(); //convert GraphResponse response to JSONObject 
            if (joMain.has("data")) { 
             JSONArray jaData = joMain.optJSONArray("data"); //find JSONArray from JSONObject 
             alFBAlbum = new ArrayList<>(); 
             for (int i = 0; i < jaData.length(); i++) {//find no. of album using jaData.length() 
              JSONObject joAlbum = jaData.getJSONObject(i); //convert perticular album into JSONObject 
              GetFacebookImages(joAlbum.optString("id")); //find Album ID and get All Images from album 
             } 
            } 
           } else { 
            Log.d("Test", response.getError().toString()); 
           } 
          } catch (JSONException e) { 
           e.printStackTrace(); 
          } 
         } 
        } 
      ).executeAsync(); 

метод GetFacebookImages

public void GetFacebookImages(final String albumId) { 
//  String url = "https://graph.facebook.com/" + "me" + "/"+albumId+"/photos?access_token=" + AccessToken.getCurrentAccessToken() + "&fields=images"; 
     Bundle parameters = new Bundle(); 
     parameters.putString("fields", "images"); 
     /* make the API call */ 
     new GraphRequest(
       AccessToken.getCurrentAccessToken(), 
       "/" + albumId + "/photos", 
       parameters, 
       HttpMethod.GET, 
       new GraphRequest.Callback() { 
        public void onCompleted(GraphResponse response) { 
      /* handle the result */ 
         Log.v("TAG", "Facebook Photos response: " + response); 
         tvTitle.setText("Facebook Images"); 
         try { 
          if (response.getError() == null) { 


           JSONObject joMain = response.getJSONObject(); 
           if (joMain.has("data")) { 
            JSONArray jaData = joMain.optJSONArray("data"); 
            lstFBImages = new ArrayList<>(); 
            for (int i = 0; i < jaData.length(); i++)//Get no. of images { 
             JSONObject joAlbum = jaData.getJSONObject(i); 
             JSONArray jaImages=joAlbum.getJSONArray("images"); get images Array in JSONArray format 
             if(jaImages.length()>0) 
             { 
              Images objImages=new Images();//Images is custom class with string url field 
              objImages.setImage_url(jaImages.getJSONObject(0).getString("source")); 
              lstFBImages.add(objImages);//lstFBImages is Images object array 
             } 
            } 

            //set your adapter here 
           } 
          } else { 
           Log.v("TAG", response.getError().toString()); 
          } 
         } catch (Exception e) { 
          e.printStackTrace(); 
         } 

        } 
       } 
     ).executeAsync(); 
    } 

Ответ первый запрос для получения альбома

{Response: responseCode: 200, graphObject: {"data":[{"created_time":"2015-11-20T08:12:11+0000","name":"Untitled Album","id":"********"}, 
{"created_time":"2015-11-19T10:21:11+0000","name":"Mobile Uploads","id":"******"}, 
{"created_time":"2015-11-19T10:23:13+0000","name":"Timeline Photos","id":"*********"}, 
{"created_time":"2015-11-19T09:32:30+0000","name":"iOS Photos","id":"*******"}, 
{"created_time":"2015-11-16T07:01:13+0000","name":"m","id":"***"}],"paging":{"cursors":{"before":"MTgzNzE3MTExOTcyMzMy","after":"MTgxOTg2NTI1NDc4NzI0"},"next":"https:\/\/graph.facebook.com\/v2.5\/USERID\/albums?access_token=*************************&limit=25&after=*********"}}, error: null} 

ответ из запроса для получения изображений с perticular Альбом

{Response: responseCode: 200, graphObject: {"data":[{"images": 
[{"height":480,"source":"https:\/\/scontent.xx.fbcdn.net\/hphotos-xfa1\/v\/t1.0-9\/***_***_***_n.jpg?oh=***&oe=5715F3A6","width":360}, 
{"height":426,"source":"https:\/\/fbcdn-photos-e-a.akamaihd.net\/hphotos-ak-xfa1\/v\/t1.0-0\/p320x320\/1169**9**9_***_**_n.jpg?oh=***&oe=***&__gda__=1457348501_***","width":320}, 
{"height":225,"source":"https:\/\/fbcdn-photos-f-a.akamaihd.net\/hphotos-ak-xpf1\/v\/t1.0-0\/p75x225\/&&&_***_***_n.jpg?oh=***&oe=56D5CA47&__gda__=***_3ac27adf32ef0b1537657dc5e88616f6","width":168}], 
"id":"&&&&539"}],"paging":{"cursors":{"before":"*******","after":"*********"}}}, error: null} 
+0

Пожалуйста, объясните свой код .thank you :) – Stella

+0

@Stella Проверьте мои измененные фотографии. –

+0

Ohkay..пожалуйста, отправьте образец ответа или отправьте мне ссылку в учебник, где вы получите this.thank u – Stella