0

So I need to get Facebook events for user's current location using graph api. According to documentation user's city is page Facebook object that has "/events" edge. So I can than get events for city using graph path /{page-id}/events, and maybe specifying since and until, but accroding do documentation if this fieds are absent than result will be for ywo last weeks.

Reading this endpoint returns an array of Event objects with the same fields as that node.

By default this will only return events within the last two weeks, use until or since parameters to modify this range.

The API says that request:

new Request(
session,
"/{page-id}/events",
null,
HttpMethod.GET,
new Request.Callback() {
    public void onCompleted(Response response) {
        /* handle the result */
    }
}
).executeAsync();

Will return page's events.

Well OK. I log in app using Facebook, than in this code:

public class FacebookActivity extends AbsActivity {

private static final String TAG = "YeedFacebookActivity";

private JSONObject location;
private JSONArray pageEvents, searchedEvents;

//this is executed in onCreate
protected void initializeFields() {
    super.initializeFields();
    ArrayList<String> permissions = new ArrayList<>(5);
    permissions.add("email");
    permissions.add("user_friends");
    permissions.add("user_location");
    permissions.add("user_events");

    final Bundle parameters = new Bundle(1);
    parameters.putString("fields", "location");

    Session.openActiveSession(this, true, permissions, new Session.StatusCallback() {
        @Override
        public void call(final Session session, SessionState sessionState, Exception e) {
            if (sessionState.isOpened()) {
                new Request(session, "/me", parameters, HttpMethod.GET, new Request.Callback() {
                    @Override
                    public void onCompleted(Response response) {
                        location = (JSONObject) response.getGraphObject().getProperty("location");
                        String cityId = "";
                        String cityName = "";
                        try {
                            cityId = location.getString("id");
                            cityName = location.getString("name");
                        } catch (JSONException e1) {
                            e1.printStackTrace();
                        }
                        //Requesting page events
                        new Request(session, cityId + "/events", null, HttpMethod.GET, new Request.Callback() {
                            @Override
                            public void onCompleted(Response response) {
                                Log.i(TAG, "PAGE\n" + response.toString());
                                pageEvents = (JSONArray) response.getGraphObject().getProperty("data");
                                Log.i(TAG, "PAGE\n" + pageEvents.toString());
                            }
                        }).executeAsync();
                        //Search by city name
                        Bundle searchParams = new Bundle(2);
                        searchParams.putString("q", cityName);
                        searchParams.putString("type", "event");
                        new Request(session, "/search", searchParams, HttpMethod.GET, new Request.Callback() {
                            @Override
                            public void onCompleted(Response response) {
                                Log.i(TAG, "SEARCH\n" + response.toString());
                                searchedEvents = (JSONArray) response.getGraphObject().getProperty("data");
                                Log.i(TAG, "SEARCH\n" + searchedEvents.toString());
                            }
                        }).executeAsync();
                    }
                }).executeAsync();
            }
        }
    });
}
}

The outer request used to retrieve user's city. First inner request returns empty data and the second inner request returns normal data about events in city, but they aren't sorted by time and I do not need all that events, just all that starts in some weeks, but sorting and then filtering them on client-side is totaly bad solution.

So my question is why data is emty? And can I somehow enchance search request?

Community
  • 1
  • 1
Konstantin Berkov
  • 1,193
  • 3
  • 14
  • 27

1 Answers1

0

There's no automatic aggregation and assignment of events to location pages. Page events have to be explicitly created by the Pages themselves. That's why you don't see any results.

Tobi
  • 31,405
  • 8
  • 58
  • 90
  • Hmm..., thanks for that! Is there any way to improve search request or the best solution would be transfer it to back-end? – Konstantin Berkov Feb 10 '15 at 13:33
  • Which search request? – Tobi Feb 10 '15 at 14:05
  • You could first use the search for `place` with a coordinate and a radius, with a specifiy search term. Then, take the resulting pages and request the `/{page_id}/events` edge for each one – Tobi Feb 10 '15 at 14:12
  • For my city it returns empty data for others it's OK. Too bad we cannot search directly events using geoposition. – Konstantin Berkov Feb 10 '15 at 15:01