I am trying to create the login with facebook in android and I am running into this issue. I am not sure what else I am failing to see or set.
I tried setting app toke / client secret but it keeps failing.
Below is my code: Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.test.app">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SplashScreenActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".FacebookLoginActivity">
<intent-filter>
<action android:name="android.intent.action.FACEBOOK_LOGIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
tools:replace="android:theme" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
FacebookLoginActivity
package com.test.app;
public class FacebookLoginActivity extends AppCompatActivity {
private TextView info;
private LoginButton loginButton;
private CallbackManager callbackManager;
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.facebook_login);
info = (TextView) findViewById(R.id.info);
loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
info.setText(
"User ID: "
+ loginResult.getAccessToken().getUserId()
+ "\n" +
"Auth Token: "
+ loginResult.getAccessToken().getToken()
);
}
@Override
public void onCancel() {
info.setText("Login attempt canceled.");
}
@Override
public void onError(FacebookException error) {
info.setText("Login attempt failed.");
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}
ERROR
Caused by: java.lang.IllegalStateException: No Client Token found, please set the Client Token.
at com.facebook.internal.Validate.hasClientToken(Validate.java:162)
at com.facebook.login.DeviceAuthDialog.startLogin(DeviceAuthDialog.java:178)
at com.facebook.login.DeviceAuthMethodHandler.showDialog(DeviceAuthMethodHandler.java:51)
at com.facebook.login.DeviceAuthMethodHandler.tryAuthorize(DeviceAuthMethodHandler.java:42)
at com.facebook.login.LoginClient.tryCurrentHandler(LoginClient.java:254)
at com.facebook.login.LoginClient.tryNextHandler(LoginClient.java:216)
at com.facebook.login.LoginClient.authorize(LoginClient.java:121)
at com.facebook.login.LoginClient.startOrContinueAuth(LoginClient.java:102)
at com.facebook.login.LoginFragment.onResume(LoginFragment.java:153)
at android.support.v4.app.Fragment.performResume(Fragment.java:2230)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1343)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1523)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1585)
at android.support.v4.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:2842)
at android.support.v4.app.FragmentController.dispatchResume(FragmentController.java:223)
at android.support.v4.app.FragmentActivity.onResumeFragments(FragmentActivity.java:509)
at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:498)
at android.app.Activity.performResume(Activity.java:6807)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3406)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3469)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2732)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
You'll need to add your app client token to your AndroidManifest like this:
<meta-data
android:name="com.facebook.sdk.ClientToken"
android:value="@string/facebook_client_token"/>
You can find your app client token in facebook dashboard -> settings -> advanced (in the security section)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With