title: Programmatic login using the Android Facebook SDK
body: <p>I've read through the documentation and source code and other relevant questions here, but I am still having an issue authorizing/logging into my app using the Facebook SDK 3 for Android.</p>
  
  <p>I do not want to use the "Login" button provided.</p>
  
  <p>Here is the relevant code:</p>
  
  <p>On the Activity.onCreate I start the session:</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      Session session = Session.getActiveSession();
      mPrefs = getSharedPreferences("facebook_storage", MODE_PRIVATE);
      String access_token = mPrefs.getString("access_token", null);
      long expires = mPrefs.getLong("access_expires", 0);
  
      if (session == null) {
          if (access_token != null) {
              SharedPreferences.Editor editor = mPrefs.edit();
              editor.putString("access_token", null);
              editor.commit();
              AccessToken accessToken = AccessToken.createFromExistingAccessToken(access_token, null, null, null, null); 
              session.open(accessToken, this);
  
          } else {
              session = new Session(getApplicationContext());
          }
          Session.setActiveSession(session);
          if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
              session.openForRead(new Session.OpenRequest(this).setCallback(this));
          } else if (session.getState().equals(SessionState.CREATED)) {
              System.out.println("Session created, no token. I guess");
              session.openForRead(new Session.OpenRequest(this).setCallback(this));
          }
      }
  </code></pre>
  
  <p>This triggers:</p>
  
  <pre><code>public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
      }
  </code></pre>
  
  <p>Which in turn triggers the next block, entering at <code>if (session.isOpened())</code>: </p>
  
  <pre><code>public void call(Session session, SessionState state, Exception exception) {
      // TODO Auto-generated method stub
      if (session == null) {
          MmfLogger.error("FacebookLogin session == null in call()");
      } else if (session.isOpened()) {
          System.out.println("Session.StatusCallback success: " + session.getState());
          Request request = new Request(session, REQUEST_FIELDS, null, null, this);
          request.executeAsync();
      }   
      if (!session.isOpened()) {
          System.out.println("session failed to open");
      }
      if (session.isOpened() &amp;&amp; session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
          Request request = new Request(session, REQUEST_FIELDS, null, null, this);
          request.executeAsync();
      } else if (session.isOpened() &amp;&amp; session.getState().equals(SessionState.CREATED)) {
          System.out.println("session isOpened and state is created");
      }
  
  }
  </code></pre>
  
  <p>And from here I get and error stating I need an active token. However, before the Request is made, I can see the token. The session has one. Where am I going wrong?</p>
  
  <p>Thank you for your time.</p>