无效范围:当我点击登录按钮时会显示ID错误?

时间:2017-08-03 07:23:53

标签: android facebook-graph-api

这是我的代码的摘录。我设置读取权限或应用图形api请求的方式有问题吗?

LoginButton loginButton = (LoginButton)findViewById(R.id.login_button);
        ArrayList<String> perList=new ArrayList<>();
        perList.add("id");
        perList.add("email");




        //loginButton.setReadPermissions("id","email","user_birthday","user_location");
        loginButton.setReadPermissions(perList);

        loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                Toast.makeText(getApplicationContext(),"facebook login success",Toast.LENGTH_SHORT).show();
                AccessToken at=loginResult.getAccessToken();
                String userId=loginResult.getAccessToken().getUserId();
                Ion.with(getApplicationContext()).load("graph.facebook.com/"+userId+"/picture?type=large").setTimeout(60*1000)
                        .asJsonObject().setCallback(new FutureCallback<JsonObject>() {
                    @Override
                    public void onCompleted(Exception e, JsonObject result) {
                        Toast.makeText(getApplicationContext(),"inOnComoplete",Toast.LENGTH_SHORT).show();
                    }
                });

            }

1 个答案:

答案 0 :(得分:0)

试试这个

 loginButton = (LoginButton) findViewById(R.id.login_button);
 loginButton.setReadPermissions(Arrays.asList("public_profile, email"));

 loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {

            Log.e("TESTCHK", "1");
            GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject object, GraphResponse response) {
                    Log.e("DAta", response.toString());

                    Log.e("TESTCHK", "2");

                    try {
                        Intent intent = new Intent(MainActivity.this, ResultActivity.class);
                        intent.putExtra("img", object.getJSONObject("picture").getJSONObject("data").getString("url"));
                        intent.putExtra("name", "Name is :  " + object.getString("name") + "\nEmail is :  " + object.getString("email"));
                        startActivity(intent);

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            });

            Bundle bundle = new Bundle();
            //bundle.putString("fields", "id,name,email,gender,birthday");
            bundle.putString("fields", "name,email,picture.type(large)");
            request.setParameters(bundle);
            request.executeAsync();

        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException error) {

            Toast.makeText(MainActivity.this, "Error while login with facebook", Toast.LENGTH_SHORT).show();

        }
    });

如果有任何疑问,请询问我