【发布时间】:2017-07-24 13:01:10
【问题描述】:
我尝试通过以下方式通过 GraphRequest 检索 facebook 用户照片 代码:
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();
通过使用此 cod,我可以获得 fb 用户相册,但它返回空数组 像这样:
enter code here {
"data":[]
},
error: null
}
你能告诉我如何获取 fb 用户照片吗?
【问题讨论】:
-
您是否要求用户获得查看其相册所需的权限...?
-
我不知道如何要求用户接受特别是访问照片的权限
-
上面的链接说它需要 user_photos 权限和 publish_action 权限,但它没有关于如何授予权限先生的信息............
-
第一个链接所做的只是解释您如何向用户请求权限...
标签: android facebook facebook-graph-api