简体   繁体   中英

Android app with Facebook SDK 3 doesn't login after sign the app

I have an app on play store, recently I updated it with new Facebook 3 SDK , all I want to do with Facebook integration is that users can post words/strings from my app to Facebook wall . I write the code as explained in Facebook "get started" and samples I downloaded , I import the library with Eclipse->properties->android->add library->and choose the Facebook SDK (as said in Facebook dev). The app works great with my own galaxy S3 & S1 directly from eclipse , it sign in correctly and post on my wall with no problems !

After I signed the app as usual and republished it on play store the problems started ! I cant log in/post on Facebook , and of course, users also can't post also.

I got this error when try to run signed app:

com.facebook.orca.protocol.base.ApiException: remote_app_id does not match stored id

I started to search for solutions , all answers were about "keyhash" .. I added 2 keyhashes as explained here Stackoverflow (debug +release key).. and also got a keyhash with code as mentioned in answer no 3 in previous link, tried different settings in Facebook dev dashboard .. "app id"/app_id is correct also, but no success !!

when I try the app with eclipse all OK , if app signed no log in, no posts .

here is my code , maybe I missed something , I really confused after 2 days without solution

public class main extends Activity {

    private Session.StatusCallback statusCallback = new SessionStatusCallback();

    private static final List<String> PERMISSIONS = Arrays.asList("publish_actions");
    @SuppressWarnings("unused")
    private boolean pendingPublishReauthorization = false;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

              //this code was for test
        try {
            PackageInfo info = getPackageManager().getPackageInfo(
                    "mypackage here", 
                    PackageManager.GET_SIGNATURES);
            for (android.content.pm.Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
                }

        } catch (NameNotFoundException e) {

        } catch (NoSuchAlgorithmException e) {

        }

        buttonLoginLogout = (ImageView)findViewById(R.id.buttonLoginLogout);
        post = (ImageButton)findViewById(R.id.fbshare);

        Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);

        Session session = Session.getActiveSession();
        if (session == null) {
            if (savedInstanceState != null) {
                session = Session.restoreSession(this, null, statusCallback, savedInstanceState);
            }
            if (session == null) {
                session = new Session(this);
            }
            Session.setActiveSession(session);
            if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
                session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
            }
        }

        updateView();

post.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                 publishStory();
            }
        });
}
@Override
        public void onStart() {
            super.onStart();

            Session.getActiveSession().addCallback(statusCallback);
        }

        @Override
        public void onStop() {
            super.onStop();
            Session.getActiveSession().removeCallback(statusCallback);
        }

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

        @Override
        protected void onSaveInstanceState(Bundle outState) {
            super.onSaveInstanceState(outState);
            Session session = Session.getActiveSession();
            Session.saveSession(session, outState);
        }

        private void updateView() {
            Session session = Session.getActiveSession();
            if (session.isOpened()) {
                buttonLoginLogout.setImageResource(R.drawable.fblogout);
                buttonLoginLogout.setOnClickListener(new OnClickListener() {
                    public void onClick(View view) { onClickLogout(); }
                });
                post.setVisibility(View.VISIBLE);
            } else {
                buttonLoginLogout.setImageResource(R.drawable.fblogin);
                buttonLoginLogout.setOnClickListener(new OnClickListener() {
                    public void onClick(View view) { onClickLogin(); }
                });
                post.setVisibility(View.INVISIBLE);
            }
        }

        private void onClickLogin() {
            Session session = Session.getActiveSession();
            if (!session.isOpened() && !session.isClosed()) {
                session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
            } else {
                Session.openActiveSession(this, true, statusCallback);
            }

        }

        private void onClickLogout() {
            Session session = Session.getActiveSession();
            if (!session.isClosed()) {
                session.closeAndClearTokenInformation();
            }

        }

        private class SessionStatusCallback implements Session.StatusCallback {
            public void call(Session session, SessionState state, Exception exception) {
                updateView();
            }
        }
        private void publishStory() {
            Session session = Session.getActiveSession();

            if (session != null){

                // Check for publish permissions    
                List<String> permissions = session.getPermissions();
                if (!isSubsetOf(PERMISSIONS, permissions)) {
                    pendingPublishReauthorization = true;
                    Session.NewPermissionsRequest newPermissionsRequest = new Session
                            .NewPermissionsRequest(this, PERMISSIONS);
                session.requestNewPublishPermissions(newPermissionsRequest);
                    return;
                }


                Request request = Request.newStatusUpdateRequest(Session.getActiveSession(), messege, new Request.Callback() {
                    public void onCompleted(Response response) {

                        Toast.makeText(main.this, "messege sent..", Toast.LENGTH_SHORT).show();
                    }
                });
                RequestAsyncTask task = new RequestAsyncTask(request);
                task.execute();
            }

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

Please help..this is my first post, I hope to find the answer :-)

another issue, maybe it will solve the problem : Do I have to wait facebook to approve my app or is not matter ?

thanks

I faced the same problem but when i signed my application by jarsigner not by eclipse it works fine in new android versions but the problem still exist on old android version like gingerbread and it may be a bug in new SDK. try it and let me know.

i solve same problem.

i use facebook sdk 3.0.2 and always remote_app_id does not match stored id error comes.

if you make your key hashs with right keystore, check your jdk version.

in jdk 1.7 , this problem comes. (i think)

when i change jdk 1.6 and the problem solved.

try it and Hope it can help you.

都谢谢你:-)我的问题是别名:应用程序名称(别名)有2个单词..所以简单的解决方案是在keystore(cmd)命令中别名的前面和结尾添加“”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM