2

我正在使用最新的 facebook SDK 开发一个 Android 应用程序,并且我正在使用此代码从 facebook 获取一些数据:

public void onFBLoginClick(View view)
{
    openActiveSession(this, true, statusCallback);
}

Session.StatusCallback statusCallback = new Session.StatusCallback() 
{
    @Override
    public void call(final Session session, SessionState state, Exception exception) 
    {
        if(session.isOpened())
        {
            Request.executeMeRequestAsync(session, new Request.GraphUserCallback() 
            {
                @Override
                public void onCompleted(GraphUser user, Response response) 
                {
                    if(user != null)
                    {
                        txtUserName.setText(session.getAccessToken());

                        String gender = user.getProperty("gender").toString();
                        String email = user.getProperty("email").toString();
                        saveUserData(user.getId(), user.getName(), user.getBirthday(), user.asMap().get("email").toString());
                        saveAccessToken(session.getAccessToken());

                        getFacebookUserProfilePicture(session.getAccessToken());
                    }
                 }
             });
         }
    }
};

private static Session openActiveSession(Activity activity, boolean allowLoginUI, Session.StatusCallback statusCallback)
{
    OpenRequest openRequest = new OpenRequest(activity);
    openRequest.setPermissions(Arrays.asList("user_birthday", "email"));
    openRequest.setCallback(statusCallback);

    Session session = new Session.Builder(activity).build();

    if(SessionState.CREATED_TOKEN_LOADED.equals(session.getState()) || allowLoginUI)
    {
        Session.setActiveSession(session);
        session.openForRead(openRequest);

        return session;
    }

    return null;
}

使用此代码,我如何获取好友列表?或者,我必须使用 REST API 吗?

4

0 回答 0