Facebook Graph API - Large Image from Event?

你。 提交于 2019-12-20 02:26:11

问题


So I'm currently trying to retrieve event images from a FB page I created for an organization I'm a part of. When make a call to graph.facebook.com/{event-id}/picture I get an absurdly small 50x50 image. However, the documentation lists a few sizes for the 'type' arg (https://developers.facebook.com/docs/graph-api/reference/event/picture/). When I specify a large type, I get a 200x200px image.

There are the 'height' and 'width' fields, but if I specify anything larger than 200px, such as height: 400 and width: 350, I get a 200x200 pic returned. From previous SO threads it looks like this didn't used to be a problem, so I'm interested in hearing if anybody else has run into this.

Note: I'm using the Koala gem (https://github.com/arsduo/koala) to interact with the API, but direct browser calls are returning the same result.


回答1:


It turns out there's an API for the cover image. You would think the Event Picture docs would at least mention it .. but it's not the case.

Cover Photo API: https://developers.facebook.com/docs/graph-api/reference/cover-photo/

This worked for me:

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();

Additionally, this can be of help to try/figure things out with the api https://developers.facebook.com/tools/explorer



来源:https://stackoverflow.com/questions/36562278/facebook-graph-api-large-image-from-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!