3

可能重复:
Android:如何使用 Graph API 从 facebook 日历获取朋友的出生日期

参考:https ://stackoverflow.com/a/13926065/1770916

我设置了获取朋友生日和列表的权限。代码如下。

private void signInWithFacebook() {

    mSessionTracker = new SessionTracker(getBaseContext(), new StatusCallback() {

        @Override
        public void call(Session session, SessionState state, Exception exception) {
        }
    }, null, false);

    String applicationId = Utility.getMetadataApplicationId(getBaseContext());
    mCurrentSession = mSessionTracker.getSession();

    if (mCurrentSession == null || mCurrentSession.getState().isClosed()) {
        mSessionTracker.setSession(null);
        Session session = new Session.Builder(getBaseContext()).setApplicationId(applicationId).build();
        Session.setActiveSession(session);
        mCurrentSession = session;
    }

    if (!mCurrentSession.isOpened()) {
        Session.OpenRequest openRequest = null;
        openRequest = new Session.OpenRequest(MainActivity.this);

        if (openRequest != null) {
            openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
            openRequest.setPermissions(Arrays.asList("user_birthday", "email", "user_location", "friends_birthday","read_friendlists" ));
            openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
            mCurrentSession.openForRead(openRequest);
        }
    }
}

但我只得到朋友 ID 和姓名。

@Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);

   if (mCurrentSession.isOpened()) {
       Request.executeMeRequestAsync(mCurrentSession, new Request.GraphUserCallback() {

              // callback after Graph API response with user object
              @Override
              public void onCompleted(GraphUser user, Response response) {
                  Log.d("AL", user.getId() + " " + user.getName() + " " + user.getInnerJSONObject());
              }
            });


        Request.executeMyFriendsRequestAsync(mCurrentSession, new Request.GraphUserListCallback() {

            @Override
            public void onCompleted(List<GraphUser> users, Response response) {
                Log.d("AL",""+response.toString());
                for (int i=0;i<users.size();i++){
                    Log.d("AL",""+users.get(i).toString());
                    welcome.setText("Done");
                }

            }
        });
        }
  }

通过使用上面的代码,我在添加权限后让用户获得额外的东西,如电子邮件、生日等,但没有让朋友额外认为生日。

我在哪里做错了???

4

2 回答 2

5

为了获取朋友信息,我们需要获取HttpConnection以下信息url

"https://graph.facebook.com/me/friends?access_token="+ mAccessToken + "&fields=id,first_name,last_name,location,picture,birthday");

在这里添加您需要的字段。我认为它会工作..

于 2012-12-22T08:44:15.623 回答
0

在这里我们得到任何东西

String url = "https://graph.facebook.com/me/friends?fields=birthday,name&access_token="+ facebook.getAccessToken(); 

用这个我过生日

 JSONObject JOAlbums = JAAlbums.getJSONObject(i);

 String date = DaysCount(JOAlbums.getString("birthday"));
于 2012-12-22T09:28:26.020 回答