Facebook Graph API - Large Image from Event?

后端 未结 1 1547
情深已故
情深已故 2021-01-21 08:56

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 a

1条回答
  •  执笔经年
    2021-01-21 09:56

    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

    0 讨论(0)
提交回复
热议问题