Unable to access facebook login?

冷暖自知 提交于 2019-12-11 15:47:10

问题


I am using Facebook's official Android SDK, and I am administrator of an app on Facebook.

I read that by default, the app is in sandbox mode and no one except administrator and developers can access it. I am using it to add Facebook login facility in my android app. However, I added my friends, who are developing the app with me as developers, but they cant log in via Facebook with their account credentials from the app. I disabled the sandbox mode for app from Facebook's app settings, still they cant access the login facility. Once they click on Facebook login button, they are redirected to the same activity without anything happening, whereas in my case, I login successfully and the app proceeds normally.

Are there any extra settings I need to do in order to make it public?

Thanks :)


回答1:


       Session.openActiveSession(this, true, new Session.StatusCallback() {

            // callback when session changes state
            @Override
            public void call(Session session, SessionState state,
                    Exception exception) {
                if (session.isOpened()) {
                    // make request to the /me API

                    List<String> permissions = session.getPermissions();
                    if (!isSubsetOf(PERMISSIONS, permissions)) {
                        pendingPublishReauthorization = true;
                        Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(
                                RegisterActivity.this, PERMISSIONS);
                        session.requestNewReadPermissions(newPermissionsRequest);
                        return;
                    }
                    Request.executeMeRequestAsync(session,
                            new Request.GraphUserCallback() {

                        // callback after Graph API response with
                        // user object
                        @Override
                        public void onCompleted(GraphUser user,
                                Response response) {
                            if (user == null) {
                                Toast.makeText(
                                        RegisterActivity.this
                                        .getApplicationContext(),
                                        "Facebook Error",
                                        Toast.LENGTH_LONG).show();

                            } else {
                                Toast.makeText(
                                        RegisterActivity.this
                                        .getApplicationContext(),
                                        user.getName()
                                        + " Logged in Successfully.",
                                        Toast.LENGTH_LONG).show();
                                GraphUser abc = user;

                                id = user.getId();
                                name = user.getName();
                                gender = user.getProperty("gender")
                                        .toString();
                                editname.setText(name);
                                username.setText(user.getUsername());
                                JSONObject jo = user
                                        .getInnerJSONObject();
                                Log.d("Details", jo.toString());
                                try {
                                    emailid.setText(user
                                            .getProperty("email")
                                            .toString());
                                } catch (Exception e1) {
                                    // TODO Auto-generated catch
                                    // block
                                    e1.printStackTrace();
                                }

                                try {
                                    location = user.getLocation()
                                            .getProperty("name")
                                            .toString();
                                } catch (Exception e) {

                                    e.printStackTrace();
                                }



                            }

                            return;
                        }

                    });

                }
            }
        });

Put onActivityResult Method

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Session.getActiveSession().onActivityResult(this, requestCode,
            resultCode, data);
}

isSubsetoff() Method

   private boolean isSubsetOf(Collection<String> subset,
        Collection<String> superset) {
    for (String string : subset) {
        if (!superset.contains(string)) {
            return false;
        }
    }
    return true;
}

and the permissions as per your need

  private static final List<String> PERMISSIONS = Arrays.asList("email",
        "user_about_me", "user_location", "user_checkins");


来源:https://stackoverflow.com/questions/17840019/unable-to-access-facebook-login

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!