ANDROID: 如何从 facebook 中的用户照片中获取图像 URL?
ANDROID: How to fetch image URLs from user photos in facebook?
我正在尝试获取所有用户的面子书照片urls.
目前我可以使用 Graph API 获取所有图像 ID。但我想要下载图像或图像 url。以下是我正在使用的代码片段..
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");
我想获取图像 urls,帮帮我。
试试这种加载图片的方式。
Picasso.with(context)
.load("https://graph.facebook.com/" + userID+ "/picture?type=large")
.into(useimg);
通过图表我得到了答案API
这是我获取所有尺寸的 facebook 图片 url 的代码
注意:我们可以根据需要添加或删除参数
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();
}
}
我正在尝试获取所有用户的面子书照片urls.
目前我可以使用 Graph API 获取所有图像 ID。但我想要下载图像或图像 url。以下是我正在使用的代码片段..
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");
我想获取图像 urls,帮帮我。
试试这种加载图片的方式。
Picasso.with(context)
.load("https://graph.facebook.com/" + userID+ "/picture?type=large")
.into(useimg);
通过图表我得到了答案API
这是我获取所有尺寸的 facebook 图片 url 的代码
注意:我们可以根据需要添加或删除参数
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();
}
}