'how to get: username and email from my facebook account in android studio

I am developing an application in java using the android studio IDE. My application has a facebook login button which is implemented in a fragment (along with its respective methods), when clicking on the login button it goes to mainActivity.class where the user data is shown (email and name of the person registering). Everything I mention works fine, the problem occurs when clicking on the facebook login button asks me for the credentials (facebook email and password ), and when displaying the user profile window (which, as I mentioned before, is developed in the main.class file) it does not show me the user data and returns a null object. Does anyone know why this happens? when I run the project and click on the button I get the following message (after showing me the mainActivity.class view): E/GraphResponse: {HttpStatus: 400, errorCode: 100, subErrorCode: 33, errorType: GraphMethodException, errorMessage: Unsupported get request. Object with ID 'xxxxx' does not exist I leave part of my code and configurations of my app below:

loggin.class:with this method I try to get the name and email of the facebook user.

protected void onCreate(Bundle savedInstanceState) {
 callbackManager = CallbackManager.Factory.create();
 loginButton = findViewById(R.id.login_button);
 loginButton.setReadPermissions(Arrays.asList("email","public_profile"));
 loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                Toast.makeText(loggin.this, "iniciado", Toast.LENGTH_SHORT).show();
                AccessToken accessToken = AccessToken.getCurrentAccessToken();
                FacebookSdk.addLoggingBehavior(LoggingBehavior.REQUESTS);
                if (accessToken != null && !accessToken.isExpired())
                {
                    GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject object, GraphResponse response) {
                            if(null != object) {
                                try
                                {
                                    Intent i = new Intent(loggin.this, MainActivity.class);
                                    startActivity(i);
                                    String email = object.getString("email");
                                    String user = object.getString("user");

                                }
                                catch (Exception ex)
                                {
                                    Toast.makeText(loggin.this, "exception", Toast.LENGTH_SHORT).show();
                                }
                            } else {
                                // call your authentication process

                            }
                        }
                    });
                    Bundle parameters = new Bundle();
                    parameters.putString("fields", "id,email");
                    request.setParameters(parameters);
                    request.executeAsync();
                }}
            @Override
            public void onCancel() {

            }

            @Override
            public void onError(FacebookException error) {

            }
        });

Manifest:Metadata file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.wuad">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.WUAD">
        <activity android:name=".login_user"></activity>
        <activity
            android:name=".MainActivity"
            android:theme="@style/Theme.MaterialComponents.DayNight.NoActionBar"></activity>
        <activity android:name=".loggin">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <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>

    </application>


</manifest>

photos of the basic configuration from facebook:

configuration_facebook

I read in forums that the problem may be due to the fact that I must leave the project in development mode as I marked in the upper rectangle, but when activating it it asks me for a privacy policy url and I don't know how to obtain it



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source