Reputation: 279
I tried to retrieve facebook user photos through GraphRequest by the following way code:
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();
by using this cod i can able to get fb user albums but it returns null array like this:
enter code here {
"data":[]
},
error: null
}
can you tell me how to get fb user photos?
Upvotes: 2
Views: 1615
Reputation: 316
You have asked to get photos
from Facebook account.After searching many hours Facebook Developers pages,I got solution for your question, I have provided link to get Facebook user photos, follow that.
Link:
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();
Upvotes: 2