I\'m trying to implement a simple activity in my android application where a user is asked to login via facebook so that the user\'s \'likes\' are retrieved. So obviously fi
private Session.StatusCallback statusCallback = new SessionStatusCallback();
private class SessionStatusCallback implements Session.StatusCallback {
@Override
public void call(final Session session, SessionState state,
Exception exception) {
try {
new_session = session;
if (state.equals(SessionState.OPENING)) {
}
if (state.equals(SessionState.OPENED)) {
}
if (state.equals(SessionState.CLOSED_LOGIN_FAILED)) {
try {
PackageInfo info = context.getPackageManager()
.getPackageInfo("your package name",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(
md.digest(), Base64.DEFAULT));
}
Session.openActiveSession((Activity) context, true,
statusCallback);
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
}
if (state.equals(SessionState.OPENED_TOKEN_UPDATED)) {
}
}
catch(Exception e){}
}
}
//if session is closed
Session.openActiveSession((Activity) context, true,
statusCallback);
I had the similar problem it was the hashkey was wrong in facebook, by following the below code you can get the hash key that has been sent to facebook. Just copy this hashkey and replace it. It will start working.
try {
PackageInfo info = getPackageManager().getPackageInfo(
"your.root.package",
PackageManager.GET_SIGNATURES);
for (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) {
}
You have to add the key hash on Facebook developer it works for me
You're missing the onActivityResult override (the last bit of the code snippet in the Getting Started Guide).
The onActivityResult is how information gets from the FB app (or the webview) back into your app, and must be overridden to call back into the session.