Facebook Graph API - 来自事件的大图像?

2023-11-30

因此,我目前正在尝试从我为我所在的组织创建的 FB 页面检索事件图像。当调用 graph.facebook.com/{event-id}/picture 时,我得到一个小得离谱的 50x50 图像。但是,文档列出了“type”参数的一些大小(https://developers.facebook.com/docs/graph-api/reference/event/picture/)。当我指定大类型时,我会得到一个 200x200px 的图像。

有“高度”和“宽度”字段,但如果我指定任何大于 200 像素的内容,例如高度:400 和宽度:350,我会返回 200x200 图片。从之前的 SO 线程来看,这似乎并不是一个问题,所以我有兴趣听听是否有其他人遇到过这个问题。

注意:我正在使用 Koala gem(https://github.com/arsduo/koala)与 API 交互,但直接浏览器调用返回相同的结果。


原来有一个用于封面图像的 API。您可能会认为事件图片文档至少会提到它..但事实并非如此。

封面照片 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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Facebook Graph API - 来自事件的大图像? 的相关文章

随机推荐