0

I’m trying to authenticate my application via facebook. I’m compiling for compileSdkVersion 25. In AndroidManifest.xml I’ve enabled <uses-permission android:name="android.permission.INTERNET" />

I’m using LoginManager tecnique called from an android Button

btnFb = (Button) findViewById(R.id.btnFb);
btnFb.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        getPermission();
        LoginManager.getInstance().logInWithReadPermissions(MainActivity.this, Arrays.asList("public_profile", "email"));
    }
});

I've associated a registerd callBack to the LoginManager

    FacebookSdk.sdkInitialize(MainActivity.this);
    callbackManager = CallbackManager.Factory.create();
    LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult result) {
            Log.i("LoginActivity","onSuccess Facebook Login"+result);
            GraphRequest request = GraphRequest.newMeRequest(
                    AccessToken.getCurrentAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject jsonObject, GraphResponse response) {
                            Log.d("","onCompleted jsonObject: "+jsonObject);
                            Log.d("","onCompleted response: "+response);
                        }
                    });
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name,link,cover,email");
            request.setParameters(parameters);
            request.executeAsync();
        }

        @Override
        public void onCancel() {
            // TODO Auto-generated method stub
            Log.i("LoginActivity","Login cancelled");
        }

        @Override
        public void onError(FacebookException e) {
            // TODO Auto-generated method stub
            Log.e("LoginActivity","ERROR: "+e.getMessage());
            e.printStackTrace();
        }
    });

And before the facebook call a request permission with the following code

private void getPermission(){
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.INTERNET)
                != PackageManager.PERMISSION_GRANTED){

                requestPermissions(new String[]{Manifest.permission.INTERNET},
                        1);

        }
    }
}

despite my attempts the authentication fails

Caught exception: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
     at com.facebook.login.LoginManager.onActivityResult(LoginManager.java:190)
     at com.facebook.login.LoginManager$1.onActivityResult(LoginManager.java:159)
     at com.facebook.internal.CallbackManagerImpl.onActivityResult(CallbackManagerImpl.java:82)
     at it.implementa.ztfacebook2.MainActivity.onActivityResult(MainActivity.java:130)
     at android.app.Activity.dispatchActivityResult(Activity.java:6597)
     at android.app.ActivityThread.deliverResults(ActivityThread.java:3726)
     at android.app.ActivityThread.handleSendResult(ActivityThread.java:3773)
     ......

Any suggestions? Thanks

Roberto Petrilli
  • 711
  • 1
  • 8
  • 22
  • 1
    Do you have the permission in the right place in the manifest? That is, outside of the `` tags? Also, you don't need to request that one at runtime. – Mike M. Dec 08 '16 at 01:39
  • 1
    Thanks Mike I put user permission tag inside the application tag, now it's ok – Roberto Petrilli Dec 08 '16 at 10:01

2 Answers2

0

Have you used these lines in Manifest of your application above ""

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Ranjan
  • 1,326
  • 18
  • 38
0

Try this check permission bcz your target Api level 25 so

Runtime permission dialogue not showing on some devices having marshmallow

Community
  • 1
  • 1
Bipin Bharti
  • 1,034
  • 2
  • 14
  • 27