Is there a way to use the facebook sdk with libgdx?

Posted by Rudy_TM on Game Development See other posts from Game Development or by Rudy_TM
Published on 2012-04-20T04:19:52Z Indexed on 2012/06/19 9:25 UTC
Read the original article Hit count: 287

Filed under:
|

I have tried to use the facebook sdk in libgdx with callbacks, but it never enters the authetication listeners, so the user never is logged in, it permits the authorization for the facebook app but it never implements the authentication interfaces :(

Is there a way to use it?

public MyFbClass()
{
    facebook = new Facebook(APPID);
    mAsyncRunner = new AsyncFacebookRunner(facebook);
    SessionStore.restore(facebook, this);

    FB.init(this, 0, facebook, this.permissions);
}


///Method for init the permissions and my listener for authetication
public void init(final Activity activity, final Facebook fb,final String[] permissions) 
    {
        mActivity = activity;
            this.fb = fb;
        mPermissions = permissions;
        mHandler = new Handler();
        async = new AsyncFacebookRunner(mFb);

        params = new Bundle();

        SessionEvents.addAuthListener(auth);

    }

///I call the authetication process, I call it with a callback from libgdx
public void facebookAction() 
    {
        // TODO Auto-generated method stub
        fb.authenticate();
    }

///It only allow the app permission, it doesnt register the events
public void authenticate()
    {
        if (mFb.isSessionValid()) 
        {
            SessionEvents.onLogoutBegin();
            AsyncFacebookRunner asyncRunner = new AsyncFacebookRunner(mFb);
            asyncRunner.logout(getContext(), new LogoutRequestListener());
            //SessionStore.save(this.mFb, getContext());
        } 
        else
        {
            mFb.authorize(mActivity, mPermissions,0 , new DialogListener());

        }
    }

public class SessionListener implements AuthListener, LogoutListener
    {

        @Override
        public void onAuthSucceed() 
        {
            SessionStore.save(mFb, getContext());
        }

        @Override
        public void onAuthFail(String error) {
        }

        @Override
        public void onLogoutBegin() {
        }

        @Override
        public void onLogoutFinish() {
            SessionStore.clear(getContext());
        }
    }

DialogListener() {

            @Override
            public void onComplete(Bundle values) 
            {
                SessionEvents.onLoginSuccess();
            }

            @Override
            public void onFacebookError(FacebookError error) 
            {
                SessionEvents.onLoginError(error.getMessage());
            }

            @Override
            public void onError(DialogError error) 
            {
                SessionEvents.onLoginError(error.getMessage());
            }

            @Override
            public void onCancel() 
            {
                SessionEvents.onLoginError("Action Canceled");
            }
}

© Game Development or respective owner

Related posts about libgdx

Related posts about facebook