Facebook Login button has no action

Asked

Viewed 558 times

10

I’m testing the Facebook Login API, but by clicking the button Log in with Facebook nothing happens, only the bar where it has the time turns black for a moment and then comes back with the color of the application set in the file styles.xml. Does not even pass any of the three attribute events facebookCallBack, onSuccess(), onError() and onCancel().

Mainactivity.class:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
}

Mainactivityfragment.class:

public class MainActivityFragment extends Fragment {

    TextView description;
    CallbackManager callbackManager;
    FacebookCallback<LoginResult> facebookCallback = new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            AccessToken accessToken = loginResult.getAccessToken();
            Profile profile = Profile.getCurrentProfile();
            if (profile != null){
                description.setText("Bem-vindo, " + profile.getFirstName());
            }
        }

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

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

    public MainActivityFragment() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_main, container, false);
        description = (TextView) view.findViewById(R.id.description);

        callbackManager = CallbackManager.Factory.create();

        LoginButton loginButton = (LoginButton) view.findViewById(R.id.login_button);
        loginButton.setReadPermissions("email");
        loginButton.setFragment(this);

        loginButton.registerCallback(callbackManager, facebookCallback);

        return inflater.inflate(R.layout.fragment_main, container, false);
    }

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

Androidmanifest.xml:

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

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <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" />
    </application>

</manifest>
  • Nothing appears in Logcat? How is the settings n Facebook panel? Generated the right hash?

  • Nothing shows up at all. I did, but I was using the wrong Cochash and I put a code in development that showed which hash I was playing for the Facebook API and I swapped the previous hash for the one I showed in the logcat with the code in development.

  • Try adding email permission together to public_profile

  • Even adding this permission did not result

  • Is the keyhash correct there in the developer panel on Facebook? Because if it is incorrect, it does not open.

  • That’s right, but I had to generate via code and he must error was not right

  • I put your same code here in my project and it’s working fine! Maybe it’s the question of yours facbook_app_id

  • Did you change the manifest as required by the documentation? https://developers.facebook.com/docs/facebook-login/android?locale=pt_BR

  • How is your logcat configured? Verbose? Only Application?

  • You wouldn’t need an onClickListener for that "button"?

  • @Giancarloabelgiulian vc tried to instantiate and implement the Facebook callback interface directly in "registerCallback"? As well: loginButton.registerCallback(callbackManager, new Facebookcallback<Loginresult>() {...

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.