1

Android Facebook SDK からユーザーのメールを取得しようとすると問題が発生します。正しいアクセス許可を設定しましたが、場合によっては機能します (ユーザーからすべてのデータを取得できます) が、一部のデバイスでは機能しないことがあります。また、サンドボックス モードを無効にし、Facebook のサイトに証明書を登録しました。お願いします、誰か助けてくれませんか?ありがとうございました!!!!

private void signInWithFacebook() {

   SessionTracker mSessionTracker = new SessionTracker(getBaseContext(), new StatusCallback() {

        @Override
        public void call(Session session, SessionState state, Exception exception) {
        }
    }, null, false);

    String applicationId = Utility.getMetadataApplicationId(getBaseContext());
    mCurrentSession = mSessionTracker.getSession();

    if (mCurrentSession == null || mCurrentSession.getState().isClosed()) {
        mSessionTracker.setSession(null);
        Session session = new Session.Builder(getBaseContext()).setApplicationId(applicationId).build();
        Session.setActiveSession(session);
        mCurrentSession = session;
    }

    if (!mCurrentSession.isOpened()) {
        Session.OpenRequest openRequest = null;
        openRequest = new Session.OpenRequest(Main.this);


        if (openRequest != null) {
            openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
            openRequest.setPermissions(Arrays.asList("user_birthday", "email"));
            openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
            mCurrentSession.openForRead(openRequest);
        }
    }
    else{
        Request.executeMeRequestAsync(mCurrentSession, new Request.GraphUserCallback() {
            public void onCompleted(GraphUser user, Response response) {


                if(!mCurrentSession.getPermissions().contains("email")){

                    id = user.getId();
                    lastname = user.getName();
                    firstname = user.getFirstName();
                    email = user.getProperty("email").toString();
                    image = "http://graph.facebook.com/" + user.getId() + "/picture?type=large";
                    link = user.getLink();
                    ages = user.getBirthday();
                    sex = user.getProperty("gender").toString();

                    new CheckUser().execute();

                }
                else{

                    Toast.makeText(getApplicationContext(), "No email", Toast.LENGTH_LONG).show();




                }



            }
        });
    }


}

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

        if (mCurrentSession.isOpened()) {
            Request.executeMeRequestAsync(mCurrentSession, new Request.GraphUserCallback() {
                public void onCompleted(GraphUser user, Response response) {

                    id = user.getId();
                    lastname = user.getName();
                    firstname = user.getFirstName();
                    email = user.getProperty("email").toString();
                    image = "http://graph.facebook.com/" + user.getId() + "/picture?type=large";
                    link = user.getLink();
                    ages = user.getBirthday();
                    sex = user.getProperty("gender").toString();


                    new CheckUser().execute();


                }
            });
        } else {
            Session.OpenRequest openRequest = null;
            openRequest = new Session.OpenRequest(Main.this);

            openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
            openRequest.setPermissions(Arrays.asList("user_birthday", "email"));
            openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);

            mCurrentSession.openForRead(openRequest);


        }

    }
4

0 に答える 0