I'm trying to implement Facebook login on Android, using the Facebook API. I've done everything the way Facebook Login Flow for Android says. My code is below.
[HIGH]public class FBSignIn extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View v = super.onCreateView(inflater, container, savedInstanceState);
setTitle("Sign In");
reloadTemplate();
return v;
}
@Override
public boolean executeCommand(BaseWebView webView, String command, String data) {
if (command.equalsIgnoreCase("login")) {
Session session = Session.getActiveSession();
if (session != null && session.isOpened()) {
loginWithFBToken(session.getAccessToken());
return;
}
Session.openActiveSession(getActivity(), true, callback);
}
return true;
}
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
// Facebook logged in...
} else if (state.isClosed()) {
//Facebook logged out...
}
}
}[/HIGH]
In my main activity I've supplied the overriden method:
[HIGH] @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}[/HIGH]
After the Session.openActiveSession() call, on the 1st entrance to onSessionsStateChange() function, I have
[HIGH]state == OPENING, exception == null.[/HIGH]
On the 2nd entrance to this function, I have
[HIGH]state == CLOSED_LOGIN_FAILED, exception == Invalid access token.[/HIGH]
What does that mean?
[HIGH]public class FBSignIn extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View v = super.onCreateView(inflater, container, savedInstanceState);
setTitle("Sign In");
reloadTemplate();
return v;
}
@Override
public boolean executeCommand(BaseWebView webView, String command, String data) {
if (command.equalsIgnoreCase("login")) {
Session session = Session.getActiveSession();
if (session != null && session.isOpened()) {
loginWithFBToken(session.getAccessToken());
return;
}
Session.openActiveSession(getActivity(), true, callback);
}
return true;
}
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
// Facebook logged in...
} else if (state.isClosed()) {
//Facebook logged out...
}
}
}[/HIGH]
In my main activity I've supplied the overriden method:
[HIGH] @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}[/HIGH]
After the Session.openActiveSession() call, on the 1st entrance to onSessionsStateChange() function, I have
[HIGH]state == OPENING, exception == null.[/HIGH]
On the 2nd entrance to this function, I have
[HIGH]state == CLOSED_LOGIN_FAILED, exception == Invalid access token.[/HIGH]
What does that mean?