所以我目前正在尝试从我为我所属的组织创建的 FB 页面中检索事件图像。当调用 graph.facebook.com/{event-id}/picture 时,我得到一张小得离谱的 50x50 图片。但是,文档列出了“类型”arg ( https://developers.facebook.com/docs/graph-api/reference/event/picture/ ) 的一些大小。当我指定一个大字体时,我得到一个 200x200 像素的图像。
有“高度”和“宽度”字段,但如果我指定任何大于 200 像素的值,例如高度:400 和宽度:350,我会返回 200x200 的图片。从以前的 SO 线程来看,这似乎不是问题,所以我很想知道是否还有其他人遇到过这个问题。
注意:我正在使用 Koala gem ( https://github.com/arsduo/koala) 与 API 交互,但直接浏览器调用返回相同的结果。
最佳答案
事实证明,封面图片有一个 API。您可能认为 Event Picture 文档至少会提到它......但事实并非如此。
封面图片 API: https://developers.facebook.com/docs/graph-api/reference/cover-photo/
这对我有用:
String eventCoverImage = "/v2.8/" + eventId;
Bundle params = new Bundle();
params.putBoolean("redirect", false);
params.putString("fields", "cover");
new GraphRequest(
AccessToken.getCurrentAccessToken(),
eventCoverImage,
params,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(final GraphResponse response) {
// thread is necessary for network call
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
String picUrlString = (String) response.getJSONObject().getJSONObject("cover").get("source");
URL imgValue = new URL(picUrlString);
Bitmap eventBitmap = BitmapFactory.decodeStream(imgValue.openConnection().getInputStream());
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
thread.start();
}
}
).executeAsync();
此外,这有助于尝试/弄清楚 api 的问题 https://developers.facebook.com/tools/explorer
关于Facebook Graph API - 来自事件的大图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36562278/