nidhi
nidhi

Reputation: 763

How to authorize my app through facebook and fetch facebook user information using Facebook SDK 3.0

I am able to login to facebook from my app by integrating Facebook latest SDK i.e. 3.0 But now I want to fetch user information and I am not able to find a way to do so. All links I am getting from google and stack is for the old version of facebook sdk. Also I would like to know how to authorize an app through facebook. In older versions we were doing it by:

Facebook facebook = new Facebook(appId);

But these things are deprecated in sdk 3.0.

Please can anyone help me out on these issues or provide links having good tutorials or sample examples!

Thanks

Upvotes: 0

Views: 1853

Answers (1)

5agado
5agado

Reputation: 2454

Once you have an open session you execute a new me request.

Session session = Session.getActiveSession();
if (session != null && session.isOpened()) {
        Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {    
        @Override
        public void onCompleted(GraphUser user, Response response) {
            if (user != null) {
                if (response.getError() == null){
                    //Do what you want with the user object
                }
                else {
                    //Do something with the error
                }
            }
        }
    });
}

As said on facebook developers page : "the user data you can access depends on the permissions a user has granted your app along with the data a user has chosen to share with apps." So you have to add the needed permission in respect to what specific fields you want.

For the app authorization you should follow the Create a Facebook App section for the Facebook SDK for android. But if you already have a working login you shouldn't need further operations.

Upvotes: 1

Related Questions