简体   繁体   中英

Facebook Android SDK login error

I am trying to implement facebook login in my app which I have already used before in my other apps. So in this app, when I try to login, the callback for login is always giving an error and I don't know what is causing it. Please correct me if my code is wrong anywhere.

public class LoginActivity extends AppCompatActivity {

Button login;
LoginButton loginButton;
CallbackManager callbackManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    AppEventsLogger.activateApp(this);
    setContentView(R.layout.activity_login);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    login = (Button) findViewById(R.id.login);
    login.setVisibility(View.GONE);

    loginButton = new LoginButton(this);
    loginButton.setReadPermissions("public_profile");

    AccessToken accessToken = AccessToken.getCurrentAccessToken();
    if (accessToken != null) {
        startActivity(new Intent(LoginActivity.this, MainActivity.class));
        finish();
    }

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            login.setVisibility(View.VISIBLE);
        }
    }, 2000);

    login.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            loginButton.performClick();
        }
    });

    callbackManager = CallbackManager.Factory.create();
    LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            // App code
            startActivity(new Intent(LoginActivity.this, MainActivity.class));
            finish();
        }

        @Override
        public void onCancel() {
            // App code
            Log.d("LoginActivity", "Cancelled");
            Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onError(FacebookException exception) {
            // App code
            Log.d("LoginActivity", "Error Occurred");
            Toast.makeText(getApplicationContext(), "Error Occurred", Toast.LENGTH_SHORT).show();
        }

    });

}

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

}

And I have also added the necessary things in my Manifest such as AppID and

<activity
        android:name="com.facebook.CustomTabActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="@string/fb_login_protocol_scheme" />
        </intent-filter>
</activity>

发生这种情况是因为该应用程序处于开发模式,因此您的应用程序公开了:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM