Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook login sdk - Android

I am trying to connect on my app with the facebook login. I did all these steps and I am facing a strange issue. So the login button works because the facebook login window appears but I am not getting the facebook token (onError is called).

I already tried all the solutions from this Questions.

This code is the same as the one in the Facebook tutorial.

mCallbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = findViewById(R.id.login_button);
    loginButton.setReadPermissions("email");
    loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.d(TAG, "facebook:onSuccess:" + loginResult);
        }

        @Override
        public void onCancel() {
            Log.d(TAG, "facebook:onCancel");
        }

        @Override
        public void onError(FacebookException error) {
            Log.d(TAG, "facebook:onError", error);
            error.printStackTrace();
        }
    });

This is my error which is a bit different from the Questions (extra: null):

09-12 21:13:40.317 29573-29573/com.xxxx.yyyy D/FACEBOOK: facebook:onError
SERVER_ERROR: [code] 1675030 [message]: Error performing query. [extra]: null
    at com.facebook.login.LoginManager.onActivityResult(LoginManager.java:219)
    at com.facebook.login.LoginManager$1.onActivityResult(LoginManager.java:174)
    at com.facebook.internal.CallbackManagerImpl.onActivityResult(CallbackManagerImpl.java:92)

AndroidManifest.xml

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

    <activity android:name="com.facebook.FacebookActivity"
        android:configChanges=
            "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:label="@string/app_name" />
    <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>

In my Build.gradle I added the Facebook SDK

    implementation 'com.facebook.android:facebook-login:[4,5)'

Activity:

public class Home extends AppCompatActivity {

private CallbackManager mCallbackManager;
private static final String TAG = "FACEBOOK";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    mCallbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = findViewById(R.id.login_button);
    loginButton.setReadPermissions(Arrays.asList("public_profile", "email"));
    loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.d(TAG, "facebook:onSuccess:" + loginResult);
        }

        @Override
        public void onCancel() {
            Log.d(TAG, "facebook:onCancel");
        }

        @Override
        public void onError(FacebookException error) {
            Log.d(TAG, "facebook:onError", error);
            error.printStackTrace();
        }
    });


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

}

Does anyone know how to solve this problem?

like image 950
carton Avatar asked Sep 12 '18 19:09

carton


People also ask

What is Facebook SDK Android?

The Facebook SDK for Android gives you access to the following features: Facebook Login — A secure and convenient way for people to log into your app or website by using their Facebook credentials. Sharing — Enable people to post to Facebook from your app. People can share, send a message, and share to stories.

Is Facebook SDK open source?

This open-source library allows you to integrate Facebook into your Android app. 👋 The SDK team is eager to learn from you!


1 Answers

Two things should be done to avoid these problems.

  1. This samples of error come only when an app you are in under development. Follow this link and select your App. Then you can do two things here. From Roles tab, you can allow login to your friends only or else select the App Review and make your app public then anyone can able to log in. And also Refresh Your Tokens.

Go to your panel and select Admin Portal. Step1 and Add tester to your Project.Step2

And also

Incorrect

loginButton.setReadPermissions(Arrays.asList("public_profile", "email"));

Correct one is

loginButton.setReadPermissions("email", "public_profile", "user_friends");

like image 145
Intra Avatar answered Oct 12 '22 18:10

Intra