Alexander Shmuratko
- Forum posts: 2
Sep 11, 2013, 10:22:05 AM via Website
Sep 11, 2013 10:22:05 AM via Website
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 (sorry, I'm a new user and cannot post links). My code is below.
In my main activity I've supplied the overriden method:
After the Session.openActiveSession() call, on the 1st entrance to onSessionsStateChange() function, I have
On the 2nd entrance to this function, I have
What does that mean?
1public class FBSignIn extends Fragment {
2 @Override
3 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
4
5 final View v = super.onCreateView(inflater, container, savedInstanceState);
6 setTitle("Sign In");
7 reloadTemplate();
8 return v;
9 }
10
11 @Override
12 public boolean executeCommand(BaseWebView webView, String command, String data) {
13
14 if (command.equalsIgnoreCase("login")) {
15 Session session = Session.getActiveSession();
16
17 if (session != null && session.isOpened()) {
18 loginWithFBToken(session.getAccessToken());
19 return;
20 }
21
22 Session.openActiveSession(getActivity(), true, callback);
23 }
24
25 return true;
26 }
27
28 private Session.StatusCallback callback = new Session.StatusCallback() {
29
30 @Override
31 public void call(Session session, SessionState state, Exception exception) {
32 onSessionStateChange(session, state, exception);
33 }
34 };
35
36 private void onSessionStateChange(Session session, SessionState state, Exception exception) {
37 if (state.isOpened()) {
38 // Facebook logged in...
39
40 } else if (state.isClosed()) {
41 //Facebook logged out...
42 }
43 }
44
45}
2 @Override
3 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
4
5 final View v = super.onCreateView(inflater, container, savedInstanceState);
6 setTitle("Sign In");
7 reloadTemplate();
8 return v;
9 }
10
11 @Override
12 public boolean executeCommand(BaseWebView webView, String command, String data) {
13
14 if (command.equalsIgnoreCase("login")) {
15 Session session = Session.getActiveSession();
16
17 if (session != null && session.isOpened()) {
18 loginWithFBToken(session.getAccessToken());
19 return;
20 }
21
22 Session.openActiveSession(getActivity(), true, callback);
23 }
24
25 return true;
26 }
27
28 private Session.StatusCallback callback = new Session.StatusCallback() {
29
30 @Override
31 public void call(Session session, SessionState state, Exception exception) {
32 onSessionStateChange(session, state, exception);
33 }
34 };
35
36 private void onSessionStateChange(Session session, SessionState state, Exception exception) {
37 if (state.isOpened()) {
38 // Facebook logged in...
39
40 } else if (state.isClosed()) {
41 //Facebook logged out...
42 }
43 }
44
45}
In my main activity I've supplied the overriden method:
1@Override
2 public void onActivityResult(int requestCode, int resultCode, Intent data) {
3 super.onActivityResult(requestCode, resultCode, data);
4 Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
5 }
2 public void onActivityResult(int requestCode, int resultCode, Intent data) {
3 super.onActivityResult(requestCode, resultCode, data);
4 Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
5 }
After the Session.openActiveSession() call, on the 1st entrance to onSessionsStateChange() function, I have
1state == OPENING, exception == null.
On the 2nd entrance to this function, I have
1state == CLOSED_LOGIN_FAILED, exception == Invalid access token.
What does that mean?
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.