0

无法打开 Facebook 会话。使用 SSO_WITH_FALLBACK 打开会话时出现 CLOSED_LOGIN_FAILED。它不是本机应用程序。在这两种情况下都试过了,即。当 1.用户已经登录到 facebook 默认原生应用并且 2.user 没有登录到 facebook 默认原生应用。

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.facebook.Session;
import com.facebook.SessionLoginBehavior;
import com.facebook.SessionState;
import com.facebook.UiLifecycleHelper;

public class PostActivity extends Activity {
Button  buttonOpenSession ;
private UiLifecycleHelper uiHelper;
Session mSession;
Session.StatusCallback callback = new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state,
            Exception exception) {
        Log.d("appState", "PostActivity " + state);
    }
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);
    setContentView(R.layout.activity_post); 
    buttonOpenSession = (Button) findViewById(R.id.buttonOpenSession);
    buttonOpenSession .setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            openSession();              
        }
    });
}

public void openSession(){
    mSession = Session.getActiveSession();      
    if (mSession == null) {
        mSession = new Session(this.getApplicationContext());           
    }       
    if (!mSession.isOpened() && !mSession.isClosed()) {
        mSession.openForRead(new Session.OpenRequest(this)
                .setCallback(callback)
                .setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK));

    } else {
        mSession = Session.openActiveSession(this, true, callback);

    }
}

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

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    uiHelper.onSaveInstanceState(outState);
}
@Override
public void onResume() {
    super.onResume();
    uiHelper.onResume();
}

@Override
public void onPause() {
    super.onPause();
    uiHelper.onPause();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    return true;
}
}
4

0 回答 0