如果我在公共自动生成的Facebook页面上知道其名称(safe_image.php.jpg),如何获得图像的直接链接? enter link description here当然使用代码
谢谢:)
编辑1:
我是在Graph API Reference /{user-id}/picture的帮助下实现的,但jason中返回的图片网址总是50x50像素,这是我的请求代码:如何将返回的大小更改为更大?
params.putString("height", "200");
params.putString("type", "normal");
params.putString("width", "200");
params.putString("fields", "picture");
new Request(session, "103139833059656", params, HttpMethod.GET, new Request.Callback()
答案 0 :(得分:1)
是的 - 可以假设您拥有页面ID。考虑这个Facebook页面: https://www.facebook.com/BCBlood
你有id - 即:
148255255232181
现在您需要做的就是调用以下行并解析响应。叫这个http get:
http://graph.facebook.com/148255255232181/picture?redirect=false&width=300&height=300
,响应将是:
{
"data": {
"height": 243,
"is_silhouette": false,
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/v/t1.0-1/10311943_731106673613700_2433559617326858334_n.jpg?oh=6f0532b666e476539b5f41b803896495&oe=5523F5C7&__gda__=1428226241_013b5598c756728eaf04d630f96256a8",
"width": 243
}
}
如您所见,响应中包含指向个人资料图片的链接。
编辑,更多细节:
Bundle params = new Bundle();
params.putString("height", "200");
params.putString("type", "normal");
params.putString("width", "200");
params.putString("redirect", "false");
Request.Callback callback = new Request.Callback() {
@Override
public void onCompleted(Response response) {
dialog.dismiss();
FacebookRequestError error = response.getError();
if(error != null) {
Log.d("FB", "Facebook error - " + error.getErrorMessage());
Log.d("FB", "Error code - " + error.getErrorCode());
Log.d("FB", "JSON Response - " + error.getRequestResult());
Log.d("FB", "Error Category - " + error.getCategory());
} else {
GraphObject graphObject = response.getGraphObject();
JSONObject dataObject =
new JSONObject((String)graphObject.getProperty("data"));
String pictureURL =
dataObject.getString("url");
// do something with pictureURL
// ......
}
}
};
Request request= new Request(session, "103139833059656/picture", params, HttpMethod.GET, new Request.Callback()
RequestAsyncTask asyncTask = new RequestAsyncTask(request);
asyncTask.execute();