2017-07-24 47 views
0

我試圖通過以下方式,通過GraphRequest檢索的Facebook用戶照片 代碼:使用此鱈魚,我可以能夠得到FB用戶相冊如何在android中獲取fb用戶照片?

enter code here final ArrayList[] alFBAlbum = new ArrayList[]{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("fb_album_response", "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[0] = new ArrayList<>(); 
           for (int i = 0; i < jaData.length(); i++) {//find no. of album using jaData.length() 
            JSONObject joAlbum = jaData.getJSONObject(i); 
            String my_id=joAlbum.optString("id");//convert perticular album into JSONObject 
            Log.d("my_facebook_id",my_id); 
            GetFacebookImages(my_id); //find Album ID and get All Images from album 
           } 
          } 
         } else { 
          Log.d("Test",response.getError().toString()); 
         } 
        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 
       } 
      } 

    ).executeAsync(); 

但它返回空數組 這樣的:

enter code here { 
    "data":[] 
}, 
    error: null 
    } 

你能告訴我如何獲得fb用戶照片嗎?

+0

你問用戶查看他們的專輯所需的權限...? – CBroe

+0

我不知道如何要求用戶接受權限,特別是訪問照片 – uma

+0

那麼從這裏開始:https://developers.facebook.com/docs/facebook-login/permissions/requesting-and-revoking什麼權限你需要,你可以在https://developers.facebook.com/docs/graph-api/reference/user/albums/ – CBroe

回答

0

您已詢問從Facebook帳戶的get photos。搜索了很多小時Facebook Developers網頁後,我得到了您的問題的解決方案,我已經提供了獲取Facebook用戶照片的鏈接,請遵循該鏈接。
鏈接: https://developers.facebook.com/docs/graph-api/reference/photo/#Reading

/* make the API call */ 
Bundle params = new Bundle(); 
bundle.putExtra("fields","images"); 

new GraphRequest(
AccessToken.getCurrentAccessToken(), 
"/"+"USER ID"+"/photos", 
params, 
HttpMethod.GET, 
new GraphRequest.Callback() { 
    public void onCompleted(GraphResponse response) { 
     /* handle the result */ 
     /* You can parse this response using Json */ 
    } 
} 
).executeAsync(); 
相關問題