Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android facebook sdk - set permissions for openActiveSession

I am trying to integrate Facebook SDK to an android app. I got the code from Facebook manual. It uses Session.openActiveSession and then request a graph user. How could I request for more permissions without using LoginButton class?

Session.openActiveSession(this, true, new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state, Exception exception) {
        onSessionStateChange(session, state, exception);

        if (session.isOpened()) {
            Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
                @Override
                public void onCompleted(GraphUser user, Response response) {
                    if (user != null) {
                        // got user graph
                    } else {
                        // could not get user graph
                    }
                }
            });
        }
    }
});

Thank you.

like image 961
Boy Avatar asked Nov 28 '22 07:11

Boy


1 Answers

Try this:

mCallback = new Session.StatusCallback() {...}; // the code you already have

Session.OpenRequest request = new Session.OpenRequest(mContext);
request.setPermissions(Arrays.asList("email", "user_birthday"));
request.setCallback(mCallback );

// get active session
Session mFacebookSession = Session.getActiveSession();
if (mFacebookSession == null || mFacebookSession.isClosed()) 
{
    mFacebookSession = new Session(mContext);
    Session.setActiveSession(mFacebookSession);
}
mFacebookSession.openForRead(request);
like image 105
Scorpio Avatar answered Dec 04 '22 05:12

Scorpio