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用戶照片嗎?
你問用戶查看他們的專輯所需的權限...? – CBroe
我不知道如何要求用戶接受權限,特別是訪問照片 – uma
那麼從這裏開始:https://developers.facebook.com/docs/facebook-login/permissions/requesting-and-revoking什麼權限你需要,你可以在https://developers.facebook.com/docs/graph-api/reference/user/albums/ – CBroe