Facebook login sdk - Android
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?
loginButton.setReadPermissions(Arrays.asList("public_profile", "email"));
I tried and didnt work...
– carton
Sep 13 '18 at 8:13
Are you on the debug build by any chance?
– Venkata Narayana
Sep 15 '18 at 19:29
What do you mean ?
– carton
Sep 15 '18 at 19:32
@carton Make sure your app is Public mode.stackoverflow.com/a/47057022/3395198
– IntelliJ Amiya
Sep 17 '18 at 11:33
2 Answers
2
Two things should be done to avoid these problems.
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");
loginButton.setReadPermissions("email", "public_profile", "user_friends");
Like i said i already tried this way to set permissions and to add test users with my second facebook account. Nothing change.
– carton
Sep 21 '18 at 21:27
Ok, Have you checked the status of Developer mode. It must be "Live".
– INTRA TUBE
Sep 21 '18 at 21:32
Firstly, you need to add privacy URL for own facebook project which you want to test facebook login. Then enable developer mode (Turn on).
– INTRA TUBE
Sep 21 '18 at 21:32
Already did. Please look at other comments.
– carton
Sep 21 '18 at 21:33
Use this command to get the Key Hashes you put in facebook configurations. [ keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64 ] .It will enquire you for a password,firstly I didn't set any, so the issue happened, when I entered android as the password.
– INTRA TUBE
Sep 21 '18 at 21:41
The problem may be caused by the status of the application in Facebook Developer Dashboard is under development !
To go live add the privacy policy URL in the Basic settings and Click on Save Changes
EDIT: Change your dependency to
implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
And create Application class as below
import android.app.Application;
import com.facebook.FacebookSdk;
import com.facebook.appevents.AppEventsLogger;
public class MyApplication extends Application
@Override
public void onCreate()
super.onCreate();
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
don't forget declare its in manifest android:name=".MyApplication"
android:name=".MyApplication"
No i already tried to make the app public ...
– carton
Sep 12 '18 at 21:37
the status should show live if you still getting error post manifest file
– 5ec20ab0
Sep 12 '18 at 22:07
The status is "live" and still not working. i edited the post to show you the manifest, but i think the problem isn't located in manifest.
– carton
Sep 13 '18 at 0:03
ok i need also see full code in activity class with build.gradle files
– 5ec20ab0
Sep 13 '18 at 12:10
I added what you need.
– carton
Sep 13 '18 at 12:19
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Try
loginButton.setReadPermissions(Arrays.asList("public_profile", "email"));– DrumRobot
Sep 13 '18 at 0:14