1

I am using ParseFacebookUtils to login to my app from Facebook.

LoginActivity's onCreate:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    loginButton = (Button)findViewById(R.id.loginButton);
    loginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {                  
            ParseFacebookUtils.logInWithReadPermissionsInBackground(LoginActivity.this,
                    Arrays.asList("public_profile", "email", "user_photos", "user_birthday"),
                    new LogInCallback() {
                        @Override
                        public void done(ParseUser user, ParseException e) {
                            if (user == null) {
                                Log.d(TAG, "Uh oh. The user cancelled the Facebook login.");
                            } else if (user.isNew()) {
                                Log.d(TAG, "User signed up and logged in through Facebook!");
                            } else {
                                Log.d(TAG, "User logged in through Facebook!");
                            }
                        }
                    }
            );
        }
    });
}

Application class onCreate:

public void onCreate() {
    super.onCreate();

    Parse.initialize(this, app_id, client_key);
    FacebookSdk.sdkInitialize(getApplicationContext());
    ParseFacebookUtils.initialize(getApplicationContext());
}

Crash error:

com.facebook.FacebookException: Log in attempt failed: LoginActivity could not be started
   at com.facebook.login.LoginManager.startLogin(LoginManager.java:382)
   at com.facebook.login.LoginManager.logInWithReadPermissions(LoginManager.java:262)
   at com.parse.FacebookAuthenticationProvider.authenticateAsync(FacebookAuthenticationProvider.java:150)
   at com.parse.ParseAuthenticationProvider.logInAsync(ParseAuthenticationProvider.java:57)
   at com.parse.ParseFacebookUtils.logInAsync(ParseFacebookUtils.java:259)
   at com.parse.ParseFacebookUtils.logInWithReadPermissionsInBackground(ParseFacebookUtils.java:155)
   at com.parse.ParseFacebookUtils.logInWithReadPermissionsInBackground(ParseFacebookUtils.java:167)
   at com.example.app.LoginActivity$1.onClick(LoginActivity.java:48)
   at android.view.View.performClick(View.java:4756)
   at android.view.View$PerformClick.run(View.java:19749)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:135)
   at android.app.ActivityThread.main(ActivityThread.java:5221)
   at java.lang.reflect.Method.invoke(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

I keep getting the above crash when tapping on the login button.

Any ideas on how to fix this?

I have set the client id for Facebook and Parse in the strings.xml

UPDATE:

Facebook SDK v4.0.1

Custom button onClick()

kRiZ
  • 2,137
  • 4
  • 25
  • 38

3 Answers3

3

@kRiZ: Yes.you forgot to add the com.facebook.FacebookActivity activity to AndroidManifest.xml.

This Activity is a necessary part of the overall Facebook SDK, but is not meant to be used directly. Add this Activity to your AndroidManifest.xml to ensure proper handling of Facebook SDK features.

Reference To use Facebook Login or Share, also add the FacebookActivity to the manifest:

<activity android:name="com.facebook.FacebookActivity"
      android:configChanges=
             "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
      android:theme="@android:style/Theme.Translucent.NoTitleBar"
      android:label="@string/app_name" />

And

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>

Where @string/facebook_app_id is your Facebook Application ID .

This is how facebook authorization process will work.

enter image description here

IntelliJ Amiya
  • 70,230
  • 14
  • 154
  • 181
2

Fixed it by adding the following in AndroidManifest.xml:

<activity android:name="com.facebook.FacebookActivity"
          android:theme="@android:style/Theme.Translucent.NoTitleBar"
          android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
          android:label="@string/app_name" />

According to this SO post, the above is needed in Facebook SDK 4.+.

kRiZ
  • 2,137
  • 4
  • 25
  • 38
0

You need to register a callback for the button before you can use it:

1.Declare a CallbackManager object:

 CallbackManager callbackManager;

2. In your onCreate method add this:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onCreate(savedInstanceState);
  FacebookSdk.sdkInitialize(getApplicationContext());
  callbackManager = CallbackManager.Factory.create();
  setContentView(R.layout.activity_login);
  ...
}

3. Define onActivityResult and add this line:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // Esto es necesario para el uso del botón de facebook
    callbackManager.onActivityResult(requestCode, resultCode, data);
}
Marta Tenés
  • 2,052
  • 1
  • 10
  • 21
  • Didn't work, sorry. `Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider` – kRiZ Sep 10 '15 at 23:10
  • Your error is due to a wrong facebook contiguration with your application, not with the login. Loot at this post, maybe you can find the solution there: http://stackoverflow.com/questions/25698419/android-failed-to-find-provider-info-for-com-facebook-wakizashi-provider-platf – Marta Tenés Sep 11 '15 at 08:02