0

I am trying to be able to handle this situation:

  1. User presses Login with Facebook:
  2. User presses Cancel in the Facebook Login page;
  3. User presses Login with Facebook again;

The problem I have is that I can't feed the application id as a resource, so instead I use this to create the facebook session:

mFacebookSession = Session.getActiveSession();
if (mFacebookSession == null)
{
    mFacebookSession = new Session.Builder(m_activity).setApplicationId(fbAppId).build();
    Session.setActiveSession(mFacebookSession);

    mFacebookStatusCallback = new FacebookStatusCallback(mFacebookSession, mFacebookWrapper);
}

To open the session, I use this:

if (!mFacebookSession.isOpened() && !mFacebookSession.isClosed())
{
    Session.OpenRequest openRequest = new Session.OpenRequest(mActivity).setCallback(mFacebookStatusCallback);
    openRequest.setPermissions(Arrays.asList("user_birthday", "email"));
    mFacebookSession.openForPublish(openRequest); //tried with openForRead too
}
else
{
    Session.openActiveSession(mActivity, true, Arrays.asList("user_birthday", "email"), mFacebookStatusCallback);
}

Everything should be fine, but because I don't feed the facebook app id in the resources, I get this :

02-27 14:53:55.011: E/AndroidRuntime(17294): java.lang.NullPointerException: Argument 'applicationId' cannot be null
02-27 14:53:55.011: E/AndroidRuntime(17294):    at com.facebook.internal.Validate.notNull(Validate.java:29)
02-27 14:53:55.011: E/AndroidRuntime(17294):    at com.facebook.Session.<init>(Session.java:281)
02-27 14:53:55.011: E/AndroidRuntime(17294):    at com.facebook.Session.<init>(Session.java:270)
02-27 14:53:55.011: E/AndroidRuntime(17294):    at com.facebook.Session$Builder.build(Session.java:1822)
02-27 14:53:55.011: E/AndroidRuntime(17294):    at com.facebook.Session.openActiveSession(Session.java:1130)
02-27 14:53:55.011: E/AndroidRuntime(17294):    at com.facebook.Session.openActiveSession(Session.java:1041)

I need to mention that the exception is thrown at step 3 (second login attempt). Trying to login the first time works. Can anyone tell me how I could feed the applicationId so that I don't get that error when trying to open the active session? Should I do anything special when handling the canceled exception? I am currently showing a toast that the operation was canceled.

Because I was asked to post the manifest, I will mention that I have the facebook activity in it:

<activity
    android:name="com.facebook.LoginActivity"
    android:label="@string/app_name" >
</activity>
Scorpio
  • 1,124
  • 1
  • 11
  • 28
  • you need to check your facebook app configuration. post your AndoridManifest.xml – SMR Feb 27 '15 at 13:12
  • I specifically mentioned in the question that I don't have the application Id in the resources. I have the facebook activity declared in the manifest. The first login attempt succeeds. Canceling and trying again fails. – Scorpio Feb 27 '15 at 13:15

1 Answers1

0

Found the problem and the solution using one of my own answers from over a year ago.

I changed the way I opened the session from what it was to this:

if (!mFacebookSession.isOpened())
{
    if(mFacebookSession.isClosed())
    {
        mFacebookSession = new Session.Builder(m_activity).setApplicationId(fbAppId).build();
        Session.setActiveSession(mFacebookSession);
    }
    Session.OpenRequest openRequest = new Session.OpenRequest(mActivity).setCallback(mFacebookStatusCallback);
    openRequest.setPermissions(Arrays.asList("user_birthday", "email"));
    mFacebookSession.openForRead(openRequest);
}
else
{
    Session.openActiveSession(mActivity, true, Arrays.asList("user_birthday", "email"), mFacebookStatusCallback);
}
Community
  • 1
  • 1
Scorpio
  • 1,124
  • 1
  • 11
  • 28