简体   繁体   English

如何从Facebook图形API获取列表

[英]how to I get list from facebook graph API

I'm trying to get the attendees from a facebook event using the graph api, I've searched numerous 我正在尝试使用图形API从Facebook活动中获取参与者,我搜索了很多
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 我在图形API资源管理器上测试了Facebook事件编号: 图形API资源管理器

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();

}

}

Solution

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? 您可以执行请求,但是您不知道如何处理JSON响应,对吗? I have no direct Java/Android knowledge on this, but that must be easy to Google for. 我对此没有直接的Java / Android知识,但这对于Google来说应该很容易。


You can request the following on the Graph API: 您可以在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 如记录所示,涉及权限: https : //developers.facebook.com/docs/graph-api/reference/v2.2/event/attending?locale=zh_CN#readperms

  • Any access token can be used to retrieve events with privacy set to OPEN. 任何访问令牌都可用于检索隐私设置为“打开”的事件。
  • A user access token can be used to retrieve any events that are visible to that person. 用户访问令牌可用于检索该人可见的任何事件。
  • An app or page token can be used to retrieve any events that were created by that app or page. 应用或页面令牌可用于检索该应用或页面创建的任何事件。

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)? 以上三种情况中的哪一种适用于您的情况(例如,事件的设置是什么,您拥有哪种访问令牌)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM