Android Facebook 登录 API returns 只有姓名和 ID

Android Facebook Login API returns only name and id

您好,我在 android 应用程序中使用 Facebook 图 Api,我可以提交请求并获得响应,但尽管我的范围是 "email", "user_birthday", "public_profile" returns只有名字和身份证。

private void onFblogin()  {
        callbackmanager = CallbackManager.Factory.create();

        // Set permissions
        LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList( "email", "user_birthday",  "public_profile"));

        LoginManager.getInstance().registerCallback(callbackmanager,
                new FacebookCallback<LoginResult>() {
                    @Override
                    public void onSuccess(LoginResult loginResult) {

                        System.out.println("Success");
                        GraphRequest.newMeRequest(
                                loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                                    @Override
                                    public void onCompleted(JSONObject json, GraphResponse response) {
                                        if (response.getError() != null) {
                                            // handle error
                                            System.out.println("ERROR");
                                        } else {
                                            System.out.println("Success");
                                            try {

                                                String jsonresult = String.valueOf(json);
                                                System.out.println("JSON Result"+jsonresult);

                                                String name = json.getString("name");
                                                String str_email = json.getString("email");
                                                String str_id = json.getString("id");


                                                //boolean loggedIn = AccessToken.getCurrentAccessToken() == null;
                                                //get profile data
                                              //  LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile"));
                                                String str_firstname = json.getString("first_name");
                                                String str_lastname = json.getString("last_name");

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

                                }).executeAsync();

                    }

                    @Override
                    public void onCancel() {
                        Log.d("facebook Login","On cancel");
                    }

                    @Override
                    public void onError(FacebookException error) {
                        Log.d("facebook Login",error.toString());
                    }
                });
    }


@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
        if (requestCode == RC_SIGN_IN) {
            // The Task returned from this call is always completed, no need to attach
            // a listener.
            Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
            handleSignInResult(task);
        } else if(requestCode == FB_SIGN_IN){
            callbackmanager.onActivityResult(requestCode, resultCode, data);
        }
    }

Gradle

implementation 'com.facebook.android:facebook-login:[4,5)'

谁能帮我获取 public_profile

中的所有信息

您没有指定任何字段,请查看文档:https://developers.facebook.com/docs/android/graph

例如:

GraphRequest request = GraphRequest.newMeRequest(
        accessToken,
        new GraphRequest.GraphJSONObjectCallback() {
            @Override
            public void onCompleted(
                   JSONObject object,
                   GraphResponse response) {
                // Application code
            }
        });
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,birthday");
request.setParameters(parameters);
request.executeAsync();

如果不指定 fields 参数,您只会在响应中获得一些默认字段。这是所有 API 个电话。

查看文档中的 "Choosing fields":https://developers.facebook.com/docs/graph-api/using-graph-api