簡體   English   中英

如何使用facebook graph api獲取需要B'day之類的權限的朋友信息

[英]How to get friends info that requires permission like B'day using facebook graph api

我有用於登錄的android Button。

下面是該按鈕的onclick偵聽器。

btnLoginFB.setOnClickListener(new View.OnClickListener() {

@
Override
public void onClick(View v) {


    Session s = new Session(Startup.this);
    Session.setActiveSession(s);
    Session.OpenRequest request = new Session.OpenRequest(Startup.this);

    List < String > permissions = new ArrayList < String > ();
    permissions.add("friends_birthday");
    permissions.add("friends_location");
    request.setPermissions(permissions);

    request.setCallback(new Session.StatusCallback() {

        @
        Override
        public void call(Session session, SessionState state, Exception exception) {

            if (session.isOpened()) {

                Request.newMyFriendsRequest(Session.getActiveSession(), new Request.GraphUserListCallback() {

                    @
                    Override
                    public void onCompleted(List < GraphUser > users, Response response) {

                        if (users != null) {


                            for (int i = 0; i < users.size(); i++) {
                                String frndLoc = "empty";

                                try {
                                    users.get(i).getLocation().getProperty("name");
                                    frndLoc = "" + users.get(i).getLocation().getProperty("name");
                                } catch (Exception e) {}

                                Toast.makeText(Startup.this, users.get(i).getBirthday() + " - " +
                                    users.get(i).getName() + "\n" +
                                    frndLoc, Toast.LENGTH_LONG).show();
                            }
                        }

                    }
                }).executeAsync();


            } // end of if (session.isOpened())
        } // end of call
    });
    s.openForRead(request);
}
});

問題是我的B'day和朋友的位置都為空。

Request friendRequest = Request.newMyFriendsRequest(activeSession, new GraphUserListCallback() {
                    @Override
                    public void onCompleted(final List<GraphUser> users, Response response) {


                            ArrayList<String> o = new ArrayList<String>();
                            for (GraphUser u : users) {
                                o.add(u.getInnerJSONObject().toString());
                            }
                            getSherlockActivity().startService(
                                    new Intent(getSherlockActivity(), InsertInDBService.class).putExtra("fbdata", o));

                        }

                    }
                });

解析響應

int count = users.size();
            for (int i = 0; i < count; i++) {
                String name = "", id = "", photoUrl = "";
                String birthday = "", location = "";
                String website = "";
                JSONObject o = null;
                try {
                    o = new JSONObject(users.get(i));
                } catch (JSONException e) {

                }
                try {
                    id = o.getString("id");
                    name = o.getString("name");
                    photoUrl = o.getJSONObject("picture").getJSONObject("data").getString("url");
                } catch (JSONException e) {
                    e.printStackTrace();
                    dbFacebookMain.deleteFACEBOOK();
                }

                try {
                    location = o.getJSONObject("location").getString("name");
                } catch (JSONException e) {

                }
                try {
                    birthday = o.getString("birthday");
                } catch (JSONException e) {

                }
                try {
                    website = o.getString("website");
                } catch (JSONException e) {

                }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM