I tried to implement Facebook login in my android app with the latest facebook SDK version. While it is working for mobile phones with facebook app not installed, but the facebook login is crashing while the phone has facebook app installed with the error as
2019-12-12 14:06:27.321 19494-19523/com.abc.xyz E/GraphResponse: {HttpStatus: 400, errorCode: 100, subErrorCode: 33, errorType: GraphMethodException, errorMessage: Unsupported get request. Object with ID '572893573534105' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api}
2019-12-12 14:06:27.656 19494-19494/com.abc.xyz W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@3860e9a
2019-12-12 14:06:29.073 19494-19494/com.abc.xyz W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@fa88da4
My facebook-login code is ->
var callbackManager: CallbackManager? = null
callbackManager = CallbackManager.Factory.create()
LoginManager.getInstance().registerCallback(callbackManager,
object : FacebookCallback<LoginResult?> {
override fun onSuccess(loginResult: LoginResult?) { // App code
}
override fun onCancel() { // App code
}
override fun onError(exception: FacebookException) { // App code
}
})
Any help is very much appreciated
Solution:
Build.gradle
implementation 'com.facebook.android:facebook-login:5.5.1'
implementation 'com.facebook.android:facebook-share:5.5.1'
java File
public void connectToFacebook() {
if (LoginManager.getInstance() != null) {
LoginManager.getInstance().logOut();
LoginManager.getInstance().registerCallback(manager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.e(TAG, "onSuccess : LoginResult" + loginResult.toString());
getAccountDetails(loginResult);
}
@Override
public void onCancel() {
Log.e(TAG, "onCancel: Login Cancel");
}
@Override
public void onError(FacebookException error) {
Snackbar.make(linearmain, "Something going wrong to connect to Facebook", Snackbar.LENGTH_LONG).show();
Log.e(TAG, "onError: Something wrong to connect to facebook" + error.getMessage());
}
});
//login with permission.
LoginManager.getInstance().logInWithPublishPermissions(this, Arrays.asList("manage_pages", "publish_pages", "publish_to_groups"));
} else {
Log.i(TAG, "connectToFacebook: LoginManager is Null");
}
}
public void getAccountDetails(final LoginResult loginResult) {
if (loginResult != null && loginResult.getAccessToken() != null) {
GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
String accountDetailsResponse = String.valueOf(object);
Log.i(TAG, "onCompleted: AccountDetailsResponse: " + accountDetailsResponse);
}
});
Bundle permission_param = new Bundle();
permission_param.putString("fields", "id, accounts, name, email, picture.width(120).height(120)");
request.setParameters(permission_param);
request.executeAsync();
} else {
Log.e(TAG, "onCancel: loginResult or AccessToken is null");
}
}
Manifest :
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<provider
android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider494396834670647"
android:exported="true" />
String.xml
<string name="facebook_app_id">Your_app_Id</string> <!-- this id for live-->
<string name="fb_login_protocol_scheme">fbYour_app_Id</string>
<string name="fb_authorities">com.facebook.app.FacebookContentProviderYour_app_Id</string>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.