Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FacebookCallback.onCancel is getting called when trying to login using facebook sdk

Tags:

I have an Android app and I am trying to use Facebook's SDK (version 4.1.0) to get a token and log in. Here is my code:

public class LoginActivity extends Activity {     private CallbackManager callbackManager;      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_login);         FacebookSdk.sdkInitialize(getApplicationContext());          callbackManager = CallbackManager.Factory.create();         LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {             @Override             public void onSuccess(LoginResult loginResult) {                 AccessToken accessToken = loginResult.getAccessToken();                 Log.v(TAG, "Facebook login was successful");                 String authToken = accessToken.getToken();                 // User authToken here:             }              @Override             public void onCancel() {                 Log.v(TAG, "Facebook login was canceled");             }              @Override             public void onError(FacebookException e) {                 Log.e(TAG, "Facebook login failed: " + e.getMessage());             }         });          Button facebook_button = (Button) findViewById(R.id.fbButton);          facebook_button.setOnClickListener(new View.OnClickListener() {             public void onClick(View v) {                 LoginManager.getInstance().logInWithReadPermissions(getActivity(), Arrays.asList("public_profile"));             }         });      }      @Override     public void onActivityResult(int requestCode, int resultCode, Intent data) {         super.onActivityResult(requestCode, resultCode, data);         callbackManager.onActivityResult(requestCode, resultCode, data);     } } 

The code switched to the Facebook app and back and OnActivityResult() is called. However, every time the callback method that is called is onCancel(). Note that I am not using the LoginButton provided by Facebook, and I have my own button (although I tried that approach and the result was the same). I double and triple checked my app ID and the keyhash generated by the app and they look correct too. So, I don't know what else may be wrong. Any help at this point is greatly appreciated.

like image 320
happyhuman Avatar asked Jun 14 '15 01:06

happyhuman


People also ask

What is Facebook's SDK?

The Facebook SDK is a set of software components that developers can include in their mobile app to understand how people use the app, run optimized marketing campaigns and enable Facebook login and social sharing.

How can I get callback from Facebook?

Testing Your CallbackGo to your Facebook profile's Apps and Websites settings tab: https://www.facebook.com/settings?tab=applications. Click the View Removed Apps and Websites link. In the popup, click the View button to the right of the application. In the window, appeared click Send Request to trigger your callback.


1 Answers

yes i was facing the same issue, resolved it by using the below code just before login

 LoginManager.getInstance().logOut(); 
like image 184
Mehroz Munir Avatar answered Sep 21 '22 19:09

Mehroz Munir