android error with facebook login on market

2019-08-20 03:35发布

问题:

When i test this app on my device with eclipse is all ok;but when i publish this app on google play store the facebook login failed!! why? help me please!! it is a simply app ("coffee break" on market);

  public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main );

            elementoInserito=(EditText)findViewById(R.id.editTextElementoInserito);
            elementoEstratto=(TextView)findViewById(R.id.textViewElementoEstratto);
            inserisci=(Button)findViewById(R.id.buttonInserisci);
            stampa=(Button)findViewById(R.id.buttonStampa);  

            facebookLogin=(Button)findViewById(R.id.facebookLogin);
            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(newSession.OpenRequest(this).setCallback(statusCallback));
                    }
                }

                inserisci.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        inizializza_array(elementoInserito);
                        elementoInserito.setText("");
                    }
                });
                updateView();
        } 
        private void updateView() {
              Session session = Session.getActiveSession();
              if (session.isOpened()) {
                facebookLogin.setOnClickListener(new OnClickListener() {
                    public void onClick(View view) { 
                        onClickLogout(); }
                });

              }
             else {
                facebookLogin.setOnClickListener(new OnClickListener() {
                    public void onClick(View view) { 
                        onClickLogin(); }
                });
            }
        } 
        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);
            }
            Bundle bundle=new Bundle();
           Session.saveSession(session,bundle);
           Toast.makeText(getApplicationContext(), 
                   "sto salvando la sessione   "+session.getState(),
                     Toast.LENGTH_LONG).show();
        }
        private void onClickLogout() {
            Session session = Session.getActiveSession();
            if (!session.isClosed()) {
                session.closeAndClearTokenInformation();
            } 
        }
        private class SessionStatusCallback implements Session.StatusCallback {
            @Override
            public void call(Session session, SessionState state, Exception exception) {
                onSessionStateChange(session, state, exception);    
                updateView();
            }
        }
        private void onSessionStateChange(Session session, SessionState state, Exception exception) {
            if (state.isOpened()) {
                Log.i(TAG, "Logged in...");
            } else if (state.isClosed()) {
                Log.i(TAG, "Logged out...");
            }
        }
        public void inizializza_array(EditText n){
            this.ins=""+n.getText();
            if(ins==""){
                 Toast.makeText(getApplicationContext(), 
                         "errore: campo vuoto",
                           Toast.LENGTH_LONG).show();
            }
            else{
                lista.add(ins);
            }
        }
        public void stampa(View v){
            if(lista.size()==0){
                elementoEstratto.setText("Inserire elementi");
            }
            else{
            Random random = new Random();
            String x = lista.get(random.nextInt(lista.size()));
                elementoEstratto.setText(x);
                lista.clear();
               try {
                  publishStory(x);
            } catch (Exception e) {
            } 
            }
        }
         public void onStart() {
                super.onStart(); 
                Session.getActiveSession().addCallback(statusCallback);
            }  
            @Override
            public void onStop() {
                super.onStop();
                Session.getActiveSession().removeCallback(statusCallback);
            }
            @Override
            protected void onSaveInstanceState(Bundle outState) {
                super.onSaveInstanceState(outState);
                Session session = Session.getActiveSession();
                Session.saveSession(session, outState);
            }
            public void publishStory(String sorteggiato) {
                Session session = Session.getActiveSession();
                try {       
                if (session != null){  
                    List<String> permissions = session.getPermissions();
                    if (!isSubsetOf(PERMISSIONS, permissions)) {
                        pendingPublishReauthorization = true;
                        Session.NewPermissionsRequest newPermissionsRequest = new Session
                                .NewPermissionsRequest(this, PERMISSIONS);
                    session.requestNewPublishPermissions(newPermissionsRequest);
                        return;
                    }
                    Bundle postParams = new Bundle();
                    postParams.putString("name",""));
                    postParams.putString("caption","");
                    postParams.putString("description","");
                    Request.Callback callback= new Request.Callback() {
                        public void onCompleted(Response response) {
                            JSONObject graphResponse = response
                                                       .getGraphObject()
                                                       .getInnerJSONObject();
                            String postId = null;
                            try {
                                postId = graphResponse.getString("id");
                            } catch (JSONException e) {
                                Log.i(TAG,
                                    "JSON error "+ e.getMessage());
                            }
                            FacebookRequestError error = response.getError();
                            if (error != null) {
                                Toast.makeText(getApplicationContext(),
                                     error.getErrorMessage(),
                                     Toast.LENGTH_SHORT).show();
                                } else {
                                    Toast.makeText(getApplicationContext(), 
                                       "shared",//postId
                                         Toast.LENGTH_LONG).show();
                            }
                        }
                    };

                    Request request = new Request(session, "me/feed", postParams, 
                                          HttpMethod.POST, callback);
                    RequestAsyncTask task = new RequestAsyncTask(request);
                    task.execute();
                    }
                else{
                    Toast.makeText(getApplicationContext(), 
                            "effettua il Login su Facebook per condividere con i tuo amici",
                              Toast.LENGTH_LONG).show();
                }
                } catch (Exception e) {
                    // TODO: handle exception
                }
                }
                private boolean isSubsetOf(Collection<String> subset, Collection<String> superset) {
                    for (String string : subset) {
                        if (!superset.contains(string)) {
                            return false;
                        }
                    }
                    return true;
                }
                @Override
                public void onActivityResult(int requestCode, int resultCode, Intent data) {
                    super.onActivityResult(requestCode, resultCode, data);
                    Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
                }    
                @Override 
                        public boolean onCreateOptionsMenu(Menu menu) {
                            Intent intent = new Intent (MainActivity.this,Info.class); 
                            //Intent intent2 = new Intent(MainActivity.this,Caffe.class);
                            menu.add("About Coffee Break").setIntent(intent);
                            //menu.add("Il caffè").setIcon(R.drawable.caffe).setIntent(intent2);
                           return true; 
                        }       
    }

i don't understand why i've this problem

回答1:

i've self resolved the problem, i did not read the relese.keystore in the rigth way I did not understand this code:

keytool -exportcert -alias myAlias -keystore ~/.your/path/release.keystore | openssl sha1 -binary | openssl base64

when I realized the code I got the right key

myAlias = alis used when i export the project

~/.your/path/release.keystore = the path where the key generated from eclipse is located, and the name of the file

Good Job