Facebook Graph API - Large Image from Event?

耗尽温柔 提交于 2019-12-01 20:22:45

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

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