• 5

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

Always getting Session state:CLOSED_LOGIN_FAILED, token:{AccessToken token:ACCESS_TOKEN_REMOVED in facebook android sdk3.0. Even when i run the examples given by the facebook sdk its authenticating and not redirecting it to next flow.it displays the previous page itself.

For some reason, the hash that the keytool is generating for me isn't the same as my app. This is what worked for me. Generate a hash using the standard code provided by facebook:

PackageInfo info = getPackageManager().getPackageInfo("<your_package_name>",  PackageManager.GET_SIGNATURES);

for (Signature signature : info.signatures)
        MessageDigest md = MessageDigest.getInstance("SHA");
        Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));

Make sure to replace "your_package_name>" with your corresponding package name. Look at logcat and grab the keyhash and enter it in your facebook app settings.

  • 51
Reply Report

The ACCESS_TOKEN_REMOVED has nothing to do with the problem. This is simply the Facebook SDK not logging the access token. So you can safely ignore that part of the error.

There are two things that are probable causes of the CLOSED_LOGIN_FAILED:

  1. You have entered incorrect credentials in the Facebook native app itself.

  2. The Android key hash entered in your app settings on developers.facebook.com does not match the key hash of the APK.

To troubleshoot #1 Open the Facebook native app and make sure you are logged in properly and can access content. If you have incorrect credentials entered in the Facebook native app (perhaps you recently changed your password) then the Facebook SDK will repeatedly try to do an SSO using the native app and report back CLOSED_LOGIN_FAILED.

To troubleshoot #2 Just follow the instructions under "Create a Facebook App" on this page, https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/.

The examples provided with the Facebook SDK will fail because the app configuration for the sample apps will not have your debug key hash registered. There are instructions for how to fix this under "Run the Samples" in the same link. Here's a quote:

Put simply, every Android app you'll create will be signed, and you will need to register each app's key hash with Facebook as a security check for authenticity - as we'll see later. But to bypass this check for the SDK samples and to get them up and running quickly, you can add your key hash to your global Facebook Developer profile.

  • 7
Reply Report

I had a similar issue - I was getting CLOSED_LOGIN_FAILED with com.facebook.FacebookOperationCanceledException: User canceled operation and I definitely wasn't canceling the operation.

After a good 7-8 hours of toying with every line of my application code, I noticed that this was set on my activity in my manifest. Removing it solved it.

  • 5
Reply Report
      • 2
    • I want to add a new line for this answer. If you do not have this launchMode, be sure not to have "android:noHistory="true"" in your manifest for your activity element.

I had the same error and I had forgotten the following line in onActivityResult of the starter activity:

Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);

Here is the whole method:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
          //do stuff
          Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
  • 5
Reply Report

We faced the same problem and was looking and googling around for a quite long time. I checked the hash key, manifest file and a lot of other things to fix this issue. We are using the older 3.23.1 version of the facebook sdk and our app was not able to connect to facebook, for certain phones only. It returned the "CLOSED_LOGIN_FAILED" state and via logcat it reported "Cannot call LoginActivity with a null calling package. This can occur if the launchMode of the caller is singleInstance".

On some phones, like the ones from Fairphone, there is a new feature added: https://fairphone.zendesk.com/hc/en-us/articles/207164396-What-is-the-Privacy-Impact-feature-

This feature avoids the reliable communication to facebook in some special circumstances. As soon as you untick it, start your app again and accept the permissions, our app was behaving like expected.

Hope this helps to avoid the grey hairs i got during fixing it.

  • 0
Reply Report

I also got this error from the SessionLoginSample for hours. It worked after I created an explicit app, SessionLoginSample, at developer.facebook.com. I copied the app id into the Android manifest, etc. and it worked. In other words, the Sample App configuration described in Facebook's Getting Started guide failed.

  • -1
Reply Report