I'm trying to get user photos link on android using Facebook SDK 4.0 and graph API. I wrote this code to parse and get photos link -
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/" + userId + "/photos",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
JSONObject json = null;
try {
json = new JSONObject(String.valueOf(response));
} catch (JSONException e) {
e.printStackTracegetJSONObject();
}
JSONArray jarray = null;
try {
jarray = json.getJSONArray("data");
} catch (JSONException e) {
e.printStackTrace();
}
for(int i = 0; i < jarray.length(); i++){
oneAlbum = null;
try {
oneAlbumURL1 = jarrayjson.getJSONObjectgetString(i"url");
} catch (JSONException e) {
einfo.printStackTracesetText(URL1.toString());
}
String URL1 = null; //
try {
URL1 = String.valueOf(oneAlbum.getJSONObject("link"));
} catch (JSONException e) {
e.printStackTrace();
}
Log.d("", URL1);
}
}
}
).executeAsync();
But its neither showing any error nor getting any URLs/links. Can anyone tell whats wrong here ?
As per new Facebook api v2.4 you need to pass the fields parameter with your facebook api url.
Like: &fields=source,id,picture
i.e.:
https://graph.facebook.com/userId/photos?access_token=APP_ACCESS_TOKEN&fields=source,id,picture
You will get the image url in source and picture tag..
EDIT
Bundle parameters = new Bundle();
parameters.putString("fields", "source,id,picture");
AccessToken.getCurrentAccessToken(),
"/" + userId + "/photos",
parameters,
HttpMethod.GET,
EDIT-2:
public void onCompleted(GraphResponse response) {
JSONObject json = response.getJSONObject();
JSONArray jarray = null;
try {
jarray = json.getJSONArray("data");
} catch (JSONException e) {
e.printStackTrace();
}