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?