2

I'm follow this tutorial to make a small app to login and say hello + user name.

The issue is: I can only login using my account, but can't log in with other account. This issue is happen with some sample code require login like HelloFacebookSample or Scrumptious. The Logcat is not show any error.

So please help me to make it login with other account. Thanks in advance!

EDIT (SOLVED): I just found the cause: My app is in Sandbox mode, just disable Sandbox mode solved problem. Thanks anyone for helps.

My code:

public class MainActivity extends Activity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // start Facebook Login
    Session.openActiveSession(this, true, new Session.StatusCallback() {

      // callback when session changes state
      @Override
      public void call(Session session, SessionState state, Exception exception) {
        if (session.isOpened()) {

          // make request to the /me API
          Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

            // callback after Graph API response with user object
            @Override
            public void onCompleted(GraphUser user, Response response) {
              if (user != null) {
                TextView welcome = (TextView) findViewById(R.id.welcome);
                welcome.setText("Hello " + user.getName() + "!");
              }
            }
          });
        }
      }
    });
  }

  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
  }

}

Screenshot when login with my account: Show hello + my name (Nguyễn Việt Anh) first screen second screen when click OK

Screenshot when login with other account: White screen When login use other account

VAdaihiep
  • 521
  • 9
  • 19
  • its not your account its your FB application. so, try to login with different user ID. – Dhaval Parmar May 09 '13 at 04:47
  • @DhawalSodha Yes, I mean how to login with different facebook user ID? I try to login using my friend facebook user ID but it's not work. – VAdaihiep May 09 '13 at 06:08

2 Answers2

1

This is expected behavior. Essentially the login for facebook is SSO (single sign on) so there is a strong expectation that the user has only one account on their device.

I myself have tried to find a way to get the Facebook SDK to allow the user to sign on to a different account but it doesn't work.

It might be possible fudge it by clearing the caches perhaps but this wouldn't help users who are using the genuine facebook app on their phone.

What I did in the end was went to the web workflow as opposed to native app. I can recommend scribe for this task.

https://github.com/fernandezpablo85/scribe-java

If you do choose to use Scribe, this is my activity for loggin in.

public class FacebookScribeLogin extends FragmentActivity{
private static final String TAG = FacebookScribeLogin.class.getSimpleName();
private final static String CALLBACK = "http://localhost:3000/";

private WebView mWebView;
private ProgressDialog mProgressDialog;

private OAuthService mAuthService;
private SyncStatusUpdaterFragment mSyncStatusUpdaterFragment;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webview);

    mWebView = (WebView) findViewById(R.id.webview);

    new GetLoginPage().execute();
}

private class GetLoginPage extends AsyncTask<Void, Void, String> {
    @Override
    protected String doInBackground(Void... voids) {
        //set up service and get request token as seen on scribe website
        //https://github.com/fernandezpablo85/scribe-java/wiki/Getting-Started
        mAuthService = new ServiceBuilder()
                .provider(FacebookApi.class)
                .apiKey(getString(R.string.facebook_api_key))
                .apiSecret(getString(R.string.facebook_api_secret))
                .scope("read_stream, publish_stream, manage_notifications, publish_actions, manage_pages")
                .callback(CALLBACK)
                .build();

        return mAuthService.getAuthorizationUrl(null);
    }

    @Override
    protected void onPostExecute(String authURL) {
        //send user to authorization page
        android.webkit.CookieManager.getInstance().removeAllCookie();

        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                //check for our custom callback protocol otherwise use default behavior
                if (url.startsWith(CALLBACK)) {
                    GetAccessToken getAccessToken = new GetAccessToken(url);
                    getAccessToken.execute();

                    return true;
                }

                if(mProgressDialog == null){
                    mProgressDialog = ProgressDialog.show(FacebookScribeLogin.this, null,
                        String.format(getString(R.string.talking_to_x), getString(R.string.facebook)), true, false);
                }

                return super.shouldOverrideUrlLoading(view, url);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                if(mProgressDialog != null){
                    mProgressDialog.hide();
                    mProgressDialog = null;
                }
            }
        });
        mWebView.loadUrl(authURL);

    }
}

private class GetAccessToken extends AsyncTask<Void, Void, Void>{
    private String mUrl, mToken, mSecret;

    private GetAccessToken(String url) {
        mUrl = url;
    }

    @Override
    protected Void doInBackground(Void... voids) {
        Uri uri = Uri.parse(mUrl);

        String verifierStr = uri.getQueryParameter("code");
        Verifier verifier = new Verifier(verifierStr);

        //save this token for practical use.
        Token accessToken = mAuthService.getAccessToken(null, verifier);
        mToken = accessToken.getToken();
        mSecret = accessToken.getSecret();

        return null;
    }

    @Override
    protected void onPostExecute(Void s) {
        //mToken - save your mToken somehwere and perhaps use a graph API call for user details
    }
}



}
Pork 'n' Bunny
  • 6,740
  • 5
  • 25
  • 32
1

You can login with different Facebook user id, after that:

  • Go to developers.facebook.com
  • choose Apps from Top
  • select wanted App from left side
  • select Edit App
  • disable sandbox mode
Julius Vainora
  • 47,421
  • 9
  • 90
  • 102
Ahmed Al Khashab
  • 373
  • 1
  • 9
  • 19