Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have following code to call facebook login dialogue in my android application,

Java
public void loginToFacebook() {
   if (access_token != null) {
      facebook.setAccessToken(access_token);
   }

   if (expires != 0) {
      facebook.setAccessExpires(expires);
   }

   if (!facebook.isSessionValid()) {
      facebook.authorize(this,
         new String[] { "email", "publish_stream" },
         new DialogListener() {
            @Override
            public void onCancel() {
               // Function to handle cancel event
            }

            @Override
            public void onComplete(Bundle values) {
               // Function to handle complete event
               // Edit Preferences and update facebook acess_token
               AsyncCallFacebookCredentials task1 = new AsyncCallFacebookCredentials();
               task1.execute();
               SharedPreferences.Editor editor = mPrefs.edit();
               editor.putString("LoginStatus", "on");
               editor.putString("access_token", facebook.getAccessToken());
               Log.e("AccessToken",facebook.getAccessToken());
               fbAccessToken_edit.putString("fbAccessToken", facebook.getAccessToken());
               fbAccessToken_edit.commit();
               editor.putLong("access_expires", facebook.getAccessExpires());
               editor.commit();
               Intent intent = new Intent(Register.this, MainActivity.class);
               startActivity(intent);
               finish();
            }

            @Override
            public void onError(DialogError error) {
               // Function to handle error
            }

            @Override
            public void onFacebookError(FacebookError fberror) {
               // Function to handle Facebook errors
            }

         });
   }
}

i am using above function in two activities, two activities have exactly same code as above, but in one activity it works perfectly but in other activity the login dialogue takes too much time to appear and after appearing if i enter credentials and press login button nothing happens.

Please help
Thanks


[edit]Code block added and indexation optimized[/edit]
Posted
Updated 15-Feb-14 1:54am
v4
Comments
Richard MacCutchan 15-Feb-14 7:52am    
You have two OnError methods which do nothing, other than consume the errors, so you have no way of knowing when failures occur.
ShreenivasCh 15-Feb-14 10:26am    
i have tried by removing comments in OnError methods and written code get error message in log cat but i didnt get any error message

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900