我试图将Facebook用户与App42链接,我可以登录到Facebook,并且可以,但是我无法将用户与App42链接,但出现异常。
我正在使用以下代码:

@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);
}


我得到以下信息:

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

最佳答案

看完代码后,我想建议你


像初始化App42API之后创建socialService对象



App42API.initialize(getApplicationContext(),
“ MY_API_KEY”,“ MY_SECRET_KEY”);社会服务socialService
= App42API.buildSocialService();



如果在初始化SDK之前创建SocialService,则会发生以下异常。



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

10-04 10:25