Facebook登录无效Parse

时间:2018-02-09 07:47:59

标签: java android facebook parse-platform facebook-login

我试图将Facebook登录功能集成到我的应用中。

当我点击"继续使用Facebook按钮"一切正常但是用户信息没有添加到解析数据库中,而且#34; logs"登录成功或失败时也不会出现在logcat中。

任何帮助都将不胜感激。

public class FacebookLoginActivity extends Activity {

LoginButton loginButtonFB;

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


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ParseAnalytics.trackAppOpenedInBackground(getIntent());

    final List<String> mPermissions = new ArrayList<String>() {{
        add("public_profile");
        add("email");
    }};


    loginButtonFB = findViewById(R.id.fb_login_button);

    loginButtonFB.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ParseFacebookUtils.logInWithReadPermissionsInBackground(FacebookLoginActivity.this, mPermissions, new LogInCallback() {
                @Override
                public void done(final ParseUser parseUser, ParseException e) {
                    if (parseUser == null) {

                        Log.d("MyApp", "Uh oh. The user cancelled the Facebook login.");

                    } else if (parseUser.isNew()) {

                        if (!ParseFacebookUtils.isLinked(parseUser)) {
                            ParseFacebookUtils.linkWithReadPermissionsInBackground(parseUser, FacebookLoginActivity.this, mPermissions, new SaveCallback() {
                                @Override
                                public void done(ParseException ex) {
                                    if (ParseFacebookUtils.isLinked(parseUser)) {
                                        Log.d("MyApp", "Woohoo, user logged in with Facebook!");

                                        Toast.makeText(FacebookLoginActivity.this, "Logged in",Toast.LENGTH_LONG).show();

                                    }
                                }
                            });
                        }
                    } else {
                        if (!ParseFacebookUtils.isLinked(parseUser)) {
                            ParseFacebookUtils.linkWithReadPermissionsInBackground(parseUser, FacebookLoginActivity.this, mPermissions, new SaveCallback() {
                                @Override
                                public void done(ParseException ex) {
                                    if (ParseFacebookUtils.isLinked(parseUser)) {
                                        Log.d("MyApp", "Woohoo, user logged in with Facebook!");
                                        Toast.makeText(FacebookLoginActivity.this, "Logged in",Toast.LENGTH_LONG).show();
                                    }
                                }
                            });
                        }

                    }

                }
            });
        }
    });
}

}

1 个答案:

答案 0 :(得分:0)

FacebookSdk.sdkInitialize(getApplicationContext());         initialiseControls();

 private void initialiseControls(){
    txtStatus=(TextView)findViewById(R.id.txtStatus);
    callbackManager = CallbackManager.Factory.create();
    login_button=(LoginButton)findViewById(R.id.login_button);
}

private void loginWithFb(){
    LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            Toast.makeText(getApplicationContext(), "LOGGED IN USING FACEBOOK !", Toast.LENGTH_LONG).show();
            //txtStatus.setText("LOGIN SUCCESSFUL!!!\n" + loginResult.getAccessToken().getToken());
            Intent testactivty = new Intent(MainActivity.this, VenuesActivity.class);
            startActivity(testactivty);
            updateUI(true);
        }

        @Override
        public void onCancel() {
            Toast.makeText(getApplicationContext(), "FAILED !", Toast.LENGTH_LONG).show();

        }

        @Override
        public void onError(FacebookException error) {
            Toast.makeText(getApplicationContext(), "ERROR !", Toast.LENGTH_LONG).show();
        }
    });

}

它适合我...希望它可以帮助你