How to login using android-simple-facebook?

469 Views Asked by At

I need to get the basic user data, like Name, Email Address, Profile Picture, Birthdate etc. I want to get this data from Facebook by offering users a login through Facebook in my android app instead of asking them to enter it manually.

I want to use android-simple-facebook https://github.com/sromku/android-simple-facebook for this purpose.

Can please someone give me a step by step instructions as to how to do it. The readme at their github account is too vague, to understand every step clearly.

1

There are 1 best solutions below

0
On

I also had the same problem in doing this in Simple Facebook. So I just made a Helper class and use its method setLogin where I want to login.

    public class FacebookHelper {

public OnLoginListener onLoginListener = null;
Button btnFacebook;
ProgressDialog mProgressDialog;
Context mContext;

public FacebookHelper(Context mContext) {
    this.mContext = mContext;
}

public void setLogin() {
    // Login listener
    onLoginListener = new OnLoginListener() {

        @Override
        public void onThinking() {
            // TODO Auto-generated method stub
        }

        @Override
        public void onException(Throwable throwable) {
            // TODO Auto-generated method stub
            Toast.makeText(mContext, throwable + "", Toast.LENGTH_SHORT)
                    .show();
        }

        @Override
        public void onFail(String reason) {
            Toast.makeText(mContext, reason + "", Toast.LENGTH_SHORT)
                    .show();

            // TODO Auto-generated method stub
        }

        @Override
        public void onLogin() {

            // TODO Auto-generated method stub
            publishPhoto();
        }

        @Override
        public void onNotAcceptingPermissions(Type type) {
            // TODO Auto-generated method stub
            Toast.makeText(mContext, type + "", Toast.LENGTH_SHORT).show();

        }
    };

}

public void publishPhoto() {

    // set privacy
    Privacy privacy = new Privacy.Builder().setPrivacySettings(
            PrivacySettings.ALL_FRIENDS).build();

    Feed photo = new Feed.Builder()
            .setName("Name")
            .setDescription("Description")
            .setPicture(
                    "http://www.bcre.com/images/laguna_beach_california_2592.jpg")

            .setPrivacy(privacy).build();

    SimpleFacebook.getInstance().publish(photo, true,
            new OnPublishListener() {

                @Override
                public void onException(Throwable throwable) {
                    mProgressDialog.dismiss();
                    Toast.makeText(mContext, throwable.getMessage(),
                            Toast.LENGTH_LONG).show();
                }

                @Override
                public void onFail(String reason) {
                    // mProgressDialog.dismiss();
                    Toast.makeText(mContext, reason, Toast.LENGTH_LONG)
                            .show();
                }

                @Override
                public void onThinking() {
                    mProgressDialog = new ProgressDialog(mContext);
                    mProgressDialog.setTitle("Please Wait");
                    mProgressDialog.setMessage("UpLoading.....");
                    mProgressDialog.setCancelable(false);
                    mProgressDialog.show();
                }

                @Override
                public void onComplete(String response) {
                    // mProgressDialog.dismiss();
                    // Toast.makeText(mOCParksContext, response,
                    // Toast.LENGTH_LONG).show();
                }
            });

}

}

and then to call its methods just do this on your click. and initiating the objects in some override methods

mFacebookHelper.setLogin();
    mSimpleFacebook.login(mFacebookHelper.onLoginListener);

    @Override
protected void onResume() {
    super.onResume();
    mSimpleFacebook = SimpleFacebook.getInstance(this);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    mSimpleFacebook.onActivityResult(this, requestCode, resultCode, data);
    super.onActivityResult(requestCode, resultCode, data);

}