I'm trying to get the attendees from a facebook event using the graph api, I've searched numerous
websites, but still have no clue how to get that "data" list. Can someone please explain me how I can get that list?
I tested the facebook event number on the graph api explorer: Graph API explorer
public class DetailActivity extends Activity {
private DatabaseHelper db;
private Session session;
private ListView attending;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
Bundle extras = getIntent().getExtras();
int tdId = extras.getInt("tdId");
db = new DatabaseHelper(this);
Event event = db.getEvent(tdId);
TextView name = (TextView)findViewById(R.id.tdName);
name.setText(event.getName());
String tdDate;
String datestring;
SimpleDateFormat simple = new SimpleDateFormat("dd MMM yy");
datestring = simple.format(event.getDate());
tdDate = String.format(datestring);
TextView date = (TextView)findViewById(R.id.tdDate);
date.setText(tdDate);
TextView place = (TextView)findViewById(R.id.tdPlace);
place.setText(event.getPlace());
new Request(
session,
"/" + event.getEvent() + "/attending",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
}
}
new Request(
session,
"/" + event.getEvent() + "/attending",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
try{
GraphObject graphObject = response.getGraphObject();
JSONObject jsonObject = graphObject.getInnerJSONObject();
Log.d("data", jsonObject.toString(0));
JSONArray array = jsonObject.getJSONArray("data");
ArrayList<Attendee> attendees = new ArrayList<Attendee>();
for(int i=0;i<array.length();i++){
JSONObject attendee = array.getJSONObject(i);
Attendee attendeeNew = new Attendee(0, attendee.getString("name"),attendee.getString("rsvp_status"), attendee.getString("id"));
attendees.add(attendeeNew);
}
ArrayAdapter<Attendee> adapter = new ArrayAdapter<Attendee>(DetailActivity.this, android.R.layout.simple_list_item_1, attendees);
final ListView listViewAttending =
(ListView) findViewById(R.id.attending);
listViewAttending.setAdapter(adapter);
}catch(JSONException e){
e.printStackTrace();
}
}
}
).executeAsync();
Update
I misread your question; you are able to perform the request, but you don't know how to process the JSON response, is that correct? I have no direct Java/Android knowledge on this, but that must be easy to Google for.
You can request the following on the Graph API:
/v2.2/{event-id}/attending
As documented, there are permissions involved: https://developers.facebook.com/docs/graph-api/reference/v2.2/event/attending?locale=en_GB#readperms
Which of the above three applies to your situation (eg what is the setting of the event and what kind of access token do you have)?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.