javaandroidfacebookapp42

Link Facebook User With App42


I am trying to Link Facebook User With App42, I can login to facebook, and that works, however I cant link the user with app42, I get an exception. I am using the following code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    App42API.initialize(getApplicationContext(), "MY_API_KEY","MY_SECRET_KEY");
    FacebookSdk.sdkInitialize(getApplicationContext());
    callbackManager = CallbackManager.Factory.create();
    setContentView(R.layout.activity_main);
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "user_friends"));
    loginButton = (LoginButton)findViewById(R.id.login_button);
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            Profile profile = Profile.getCurrentProfile();
            AccessToken token = AccessToken.getCurrentAccessToken();

            String userName = profile.getId();
            String accessToken = token.toString();
            socialService.linkUserFacebookAccount(userName, accessToken, new App42CallBack() {
                public void onSuccess(Object response) {
                    Social social = (Social) response;
                    System.out.println("userName is " + social.getUserName());
                    System.out.println("fb Access Token is " + social.getFacebookAccessToken());
                    String jsonResponse = social.toString();
                }

                public void onException(Exception ex) {
                    System.out.println("Exception Message" + ex.getMessage());
                }
            });

        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException e) {

        }
    });

}

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

I am getting the following:

07-06 16:27:16.594    9810-9862/tk.hasankassem.tapo I/System.out﹕ (HTTPLog)-Static: isSBSettingEnabled false
07-06 16:27:16.954    9810-9810/tk.hasankassem.tapo I/System.out﹕ Installation.getSession : /data/data/tk.hasankassem.tapo/files/SESSION: open failed: ENOENT (No such file or directory)
07-06 16:27:16.954    9810-9810/tk.hasankassem.tapo I/System.out﹕ Installation.getUser : /data/data/tk.hasankassem.tapo/files/USER: open failed: ENOENT (No such file or directory)
07-06 16:27:16.964    9810-9868/tk.hasankassem.tapo I/System.out﹕ Exception :com.shephertz.app42.paas.sdk.android.App42Exception: java.lang.IllegalArgumentException: key.length == 0
07-06 16:27:16.964    9810-9868/tk.hasankassem.tapo I/System.out﹕ Exception Messagejava.lang.IllegalArgumentException: key.length == 0
07-06 16:27:16.969    9810-9867/tk.hasankassem.tapo I/System.out﹕ Thread-121146(ApacheHTTPLog):Reading from variable values from setDefaultValuesToVariables
07-06 16:27:16.969    9810-9867/tk.hasankassem.tapo I/System.out﹕ Thread-121146(ApacheHTTPLog):isSBSettingEnabled false
07-06 16:27:16.974    9810-9867/tk.hasankassem.tapo I/System.out﹕ Thread-121146(ApacheHTTPLog):isShipBuild true
07-06 16:27:16.974    9810-9867/tk.hasankassem.tapo I/System.out﹕ Thread-121146(ApacheHTTPLog):SmartBonding Enabling is false, SHIP_BUILD is true, log to file is false, DBG is false

Solution

  • After go through with the code I would like to suggest you

    1. Create socialService object after initializing the App42API like

    App42API.initialize(getApplicationContext(), "MY_API_KEY","MY_SECRET_KEY"); SocialService socialService =App42API.buildSocialService();

    1. The below exception occurs if you are creating SocialService before Initializing the SDK.

    Messagejava.lang.IllegalArgumentException: key.length == 0