在使用android尝试facebook身份验证时缺少INTERNET权限

时间:2016-12-08 01:37:46

标签: android facebook

我正在尝试通过Facebook验证我的申请。我正在编译compileSdkVersion 25。 在AndroidManifest.xml中,我启用了 <uses-permission android:name="android.permission.INTERNET" />

我正在使用从Android Button

调用的LoginManager tecnique
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"));
    }
});

我已将注册的callBack与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();
        }
    });

在facebook之前使用以下代码调用请求权限

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);

        }
    }
}

尽管我尝试了身份验证失败

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)
     ......

有什么建议吗?感谢

2 个答案:

答案 0 :(得分:0)

您是否在“”

上面的应用程序的清单中使用了这些行
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

答案 1 :(得分:0)

尝试此检查权限bcz你的目标Api等级25所以

Runtime permission dialogue not showing on some devices having marshmallow