我正在尝试获取所有用户脸书照片网址 目前,我可以使用Graph API获取所有图像ID。但我想要下载图片或图片网址。以下是我正在使用的代码段..
new GraphRequest(
AccessToken.getCurrentAccessToken(),
// "/"+userId+"/albums",
"/"+userId+"/photos/uploaded",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
System.out.println("photosResponse:"+response); }
}
).executeAsync();
样本回复:
{
Response: responseCode: 200,
graphObject: {
"data": [
{
"created_time": "2018-01-02T14:30:19+0000",
"id": "12345678"
},
{
"created_time": "2017-12-30T11:44:26+0000",
"id": "23456789"
}]}}
并添加了这些权限
loginButton.setReadPermissions("email", "user_birthday", "user_posts", "user_photos");
我想获取图片网址,帮助我。
答案 0 :(得分:1)
我在完成图谱API后得到了答案
这是我的代码,以获取所有尺寸的脸书图片网址
注意:我们可以根据我们的要求添加或删除参数
public void syncImagesToDB(String FBuserId) {
if (FBuserId != null && FBuserId.length() > 0) {
Bundle fb_params = new Bundle();
fb_params.putString("fields", "id, name,created_time, link,images");
final ArrayList<String> imageURL_list = new ArrayList<>();
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/" + FBuserId + "/photos/uploaded",
fb_params,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
System.out.println("photosResponse:" + response);
try {
JSONObject jsonObject = response.getJSONObject();
Log.e("jsonObject ", " -> " + jsonObject);
//JSONObject jsonObject = new JSONObject(String.valueOf(response));
JSONArray jsonArray_data = jsonObject.optJSONArray("data");
for (int i = 0; i < jsonArray_data.length(); i++) {
JSONObject album = null;
album = jsonArray_data.optJSONObject(i);
String id = album.optString("id");
String link = album.optString("link");
String created_time = album.optString("created_time");
JSONArray images_arr = album.optJSONArray("images");
if (images_arr.length() > 0) {
JSONObject image_obj = images_arr.optJSONObject(0);
String source_url = image_obj.optString("source");
imageURL_list.add(source_url);
}
Bundle params1 = new Bundle();
params1.putString("fields", "id, name, link");
}
if (imageURL_list != null && imageURL_list.size() > 0) {
}
System.out.println("total uploaded images:" + imageURL_list.size());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
).executeAsync();
}
}
答案 1 :(得分:0)
尝试这种方式加载图片。
Picasso.with(context)
.load("https://graph.facebook.com/" + userID+ "/picture?type=large")
.into(useimg);