gpt4 book ai didi

android - 如何在android中获取fb用户照片?

转载 作者:搜寻专家 更新时间:2023-11-01 09:33:29 25 4
gpt4 key购买 nike

我尝试通过以下方式通过 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用户照片吗?

最佳答案

您已要求从 Facebook 帐户获取照片。在搜索了许多小时的 Facebook 开发人员页面后,我找到了您问题的解决方案,我提供了获取 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();

关于android - 如何在android中获取fb用户照片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45281351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com