FB SDK not working on OS 7

2020-07-27 05:25发布

问题:

I am implementing FB in one of my app.I am using jar 0.8.25. Its working fine on all simulators from 5 to 7.1.And for devices works only for OS 5 and 6 but not working on device 7 and 7.1.For OS 7 after log in success it remains on FB page it doesn't redirect back. and when i press back button, i get error encountered unable to refresh access token with try again button.

When analyzing on console it never finds access token single time for OS 7.while for 5 and 6 its working perfectly.

Please tell what may cause the issue.

Thanks,

回答1:

This isn't a solution to your specific problem. I mentioned in the comments that I'm using an interface. So I'm posting here as its too much for the comment section. It is also not the COMPLETE solution, you will need to handle the flow and expired tokens, this is just to show you the logic of how I did this.

For my interface I open a browserfield to the Oauth url: https://www.facebook.com/dialog/oauth?client_id=<APP_ID>&response_type=token&redirect_uri=http://www.facebook.com/connect/login_success.html&scope=publish_actions

And I add a listener to this browser to listen for the redirects after login. Once you have the access token, you should persist it and close the browserfield.

private class OAuthScreen extends MainScreen
    {
        BrowserField browser_field;
        LoadingDialog loading_dialog;

        public OAuthScreen(final Command task)
        {
            super(VERTICAL_SCROLL | HORIZONTAL_SCROLL);
            BrowserFieldConfig browserConfig = new BrowserFieldConfig();
            browserConfig.setProperty(BrowserFieldConfig.VIEWPORT_WIDTH, new Integer(Display.getWidth()));

            browser_field = new BrowserField(browserConfig);
            browser_field.addListener(new BrowserFieldListener()
            {
                public void documentCreated(BrowserField browserField, ScriptEngine scriptEngine, Document document) throws Exception
                {
                    int index = browserField.getDocumentUrl().indexOf("#access_token=");
                    if (index == -1)
                    {
                        super.documentCreated(browserField, scriptEngine, document);
                    }
                    else
                    {
                        access_token = browserField.getDocumentUrl().substring(index + "#access_token=".length(), browserField.getDocumentUrl().indexOf("&"));

                        PersistentObject store = PersistentStore.getPersistentObject(STORE_KEY);
                        FacebookTokens store_tokens = new FacebookTokens();
                        store_tokens.access_token = access_token;
                        store.setContents(store_tokens);
                        store.commit();

                        if (task != null) task.execute();
                        OAuthScreen.this.close();
                    }
                }

                public void documentLoaded(BrowserField browserField, Document document) throws Exception
                {
                    super.documentLoaded(browserField, document);
                    loading_dialog.close();
                }
            });
            // whatever loading dialog you want, this sometimes takes a while to open
            loading_dialog = LoadingDialog.push(loading_field);

            add(browser_field);
            browser_field.requestContent("https://www.facebook.com/dialog/oauth?client_id="+APP_ID+"&response_type=token&redirect_uri=http://www.facebook.com/connect/login_success.html&scope=publish_actions");
        }
    }

The callback task is just for if I want to perform a call directly after login.

Now just perform API calls as you need them. API methods here https://developers.facebook.com/docs/graph-api/reference/v2.0/ Methods that require the access token, should have it appended to the url such as, https://graph.facebook.com/me/feed?access_token=" + access_token

Be aware that clearing your access token won't clear the token stored in the browser field. And will mean that you can't login next time (because the browser is still logged in). So if you want to logout you need to open this link in a browserfield before clearing your local access token "https://www.facebook.com/logout.php?next=http://www.facebook.com/connect/login_success.html&access_token=" + access_token Clearing the cookies of the browser should suffice, but I haven't found a way to do this.