0

私は、サードパーティのアプリケーション Facebook を使用しているブラックベリー アプリケーションに取り組んでいます。

さて、私の問題は、最初にメッセージを投稿するときに、Facebookのログイン画面にリダイレクトされ、メッセージが投稿されることです。しかし、アプリケーションからログアウトし、再度ログインしてFacebookにメッセージを投稿すると、認証情報を要求せずにメッセージが直接投稿されます。

Facebookにログインするための以下のコード:

    public class FacebookMain implements ActionListener{// extends MainScreen implements ActionListener {

        // Constants
        public final static String NEXT_URL = "http://www.facebook.com/connect/login_success.html";
        public final static String APPLICATION_ID ="261890490596037"; 
        private final static long persistentObjectId = 0x854d1b7fa43e3577L;
        //APPLICATION SECRET ID="f7e096af696ef81e72268f49a6381a8d"

        static final String ACTION_ENTER = "updateStatus";
        static final String ACTION_SUCCESS = "statusUpdated";
        static final String ACTION_ERROR = "error";
        private ActionScreen actionScreen;

        private PersistentObject store;

        private LoginScreen loginScreen;
        private LogoutScreen logoutScreen;
        private HomeScreen homeScreen;
        private UpdateStatusScreen updateStatusScreen;
        private RecentUpdatesScreen recentUpdatesScreen;
        private UploadPhotoScreen uploadPhotoScreen;
        private FriendsListScreen friendsListScreen;
        private PokeFriendScreen pokeFriendScreen;
        private PostWallScreen postWallScreen;
        private SendMessageScreen sendMessageScreen;

        private String postMessage;

        private FacebookContext fbc;
        public static boolean isWallPosted=false;

        public FacebookMain(String postMessge) {
            this.postMessage=postMessge;

            checkPermissions();
            init();

            if ((fbc != null) && fbc.hasValidAccessToken()) {

                /*homeScreen = new HomeScreen(fbc);
                homeScreen.addActionListener(this);
                UiApplication.getUiApplication().pushScreen(homeScreen);*/

                try {
                    new FBUser("me", fbc.getAccessToken()).setStatus(postMessage);
                    actionScreen=new ActionScreen();
                    actionScreen.fireAction(ACTION_SUCCESS);
                    Dialog.alert("Wall Posted ");
                    isWallPosted=true;
                    //UiApplication.getUiApplication().popScreen(loginScreen);
                } catch (Exception e) {
                    actionScreen.fireAction(ACTION_ERROR, e.getMessage());
                    //UiApplication.getUiApplication().popScreen(loginScreen);
                }

            } else {

                loginScreen = new LoginScreen(fbc,postMessge);
                loginScreen.addActionListener(this);
                UiApplication.getUiApplication().pushScreen(loginScreen);
            }
        }

        private void init() {
            store = PersistentStore.getPersistentObject(persistentObjectId);
            synchronized (store) {
                if (store.getContents() == null) {
                    store.setContents(new FacebookContext(NEXT_URL, APPLICATION_ID));
                    store.commit();
                }
            }
            fbc = (FacebookContext) store.getContents();
        }

        private void checkPermissions() {

            ApplicationPermissionsManager apm = ApplicationPermissionsManager.getInstance();
            ApplicationPermissions original = apm.getApplicationPermissions();

            if ((original.getPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION) == ApplicationPermissions.VALUE_ALLOW) && (original.getPermission(ApplicationPermissions.PERMISSION_DEVICE_SETTINGS) == ApplicationPermissions.VALUE_ALLOW) && (original.getPermission(ApplicationPermissions.PERMISSION_CROSS_APPLICATION_COMMUNICATION) == ApplicationPermissions.VALUE_ALLOW) && (original.getPermission(ApplicationPermissions.PERMISSION_INTERNET) == ApplicationPermissions.VALUE_ALLOW) && (original.getPermission(ApplicationPermissions.PERMISSION_SERVER_NETWORK) == ApplicationPermissions.VALUE_ALLOW) && (original.getPermission(ApplicationPermissions.PERMISSION_EMAIL) == ApplicationPermissions.VALUE_ALLOW)) {
                return;
            }

            ApplicationPermissions permRequest = new ApplicationPermissions();
            permRequest.addPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION);
            permRequest.addPermission(ApplicationPermissions.PERMISSION_DEVICE_SETTINGS);
            permRequest.addPermission(ApplicationPermissions.PERMISSION_CROSS_APPLICATION_COMMUNICATION);
            permRequest.addPermission(ApplicationPermissions.PERMISSION_INTERNET);
            permRequest.addPermission(ApplicationPermissions.PERMISSION_SERVER_NETWORK);
            permRequest.addPermission(ApplicationPermissions.PERMISSION_EMAIL);
            permRequest.addPermission(ApplicationPermissions.PERMISSION_INTERNET);
            permRequest.addPermission(ApplicationPermissions.PERMISSION_AUTHENTICATOR_API);
            permRequest.addPermission(ApplicationPermissions.PERMISSION_SERVER_NETWORK);
            permRequest.addPermission(ApplicationPermissions.PERMISSION_WIFI);

            boolean acceptance = ApplicationPermissionsManager.getInstance().invokePermissionsRequest(permRequest);

            if (acceptance) {
                // User has accepted all of the permissions.
                return;
            } else {
            }
        }

        public void saveContext(FacebookContext pfbc) {
            synchronized (store) {
                store.setContents(pfbc);
                System.out.println(pfbc);
                store.commit();
            }
        }

        public void logoutAndExit() {
            saveContext(null);
            logoutScreen = new LogoutScreen(fbc);
            logoutScreen.addActionListener(this);
        }

        public void saveAndExit() {
            saveContext(fbc);
            exit();
        }

        private void exit() {
            AppenderFactory.close();
            System.exit(0);
        }

        public void onAction(Action event) {/*

            if (event.getSource() == loginScreen) {
                if (event.getAction().equals(LoginScreen.ACTION_LOGGED_IN)) {
                    try {
                        fbc.setAccessToken((String) event.getData());
                        try {
                            new FBUser("me", fbc.getAccessToken()).setStatus(postMessage);
                            actionScreen=new ActionScreen();
                            actionScreen.fireAction(ACTION_SUCCESS);
                            Dialog.alert("Wall Posted ");
                        } catch (Exception e) {
                            actionScreen.fireAction(ACTION_ERROR, e.getMessage());
                        }
                        try {
                            if (homeScreen == null) {
                                homeScreen = new HomeScreen(fbc);
                                homeScreen.addActionListener(this);
                            }
                            UiApplication.getUiApplication().pushScreen(homeScreen);

                        } catch (Exception e) {
                            e.printStackTrace();
                            Dialog.alert("Error: " + e.getMessage());
                        }

                    } catch (Throwable t) {
                        t.printStackTrace();
                        Dialog.alert("Error: " + t.getMessage());
                    }

                } else if (event.getAction().equals(LoginScreen.ACTION_ERROR)) {
                    Dialog.alert("Error: " + event.getData());
                }

            } else if (event.getSource() == logoutScreen) {
                if (event.getAction().equals(LogoutScreen.ACTION_LOGGED_OUT)) {
                    exit();
                }

            } else if (event.getSource() == homeScreen) {
                if (event.getAction().equals(UpdateStatusScreen.ACTION_ENTER)) {
                    if (updateStatusScreen == null) {
                        updateStatusScreen = new UpdateStatusScreen(fbc);
                        updateStatusScreen.addActionListener(this);
                    }
                    UiApplication.getUiApplication().pushScreen(updateStatusScreen);
                    try {
                        new FBUser("me", fbc.getAccessToken()).setStatus("");
                        actionScreen=new ActionScreen();
                        actionScreen.fireAction(ACTION_SUCCESS);
                    } catch (Exception e) {
                        actionScreen.fireAction(ACTION_ERROR, e.getMessage());
                    }

                } else if (event.getAction().equals(RecentUpdatesScreen.ACTION_ENTER)) {
                    if (recentUpdatesScreen == null) {
                        recentUpdatesScreen = new RecentUpdatesScreen(fbc);
                        recentUpdatesScreen.addActionListener(this);
                    }
                    recentUpdatesScreen.loadList();
                    UiApplication.getUiApplication().pushScreen(recentUpdatesScreen);

                } else if (event.getAction().equals(UploadPhotoScreen.ACTION_ENTER)) {
                    if (uploadPhotoScreen == null) {
                        uploadPhotoScreen = new UploadPhotoScreen(fbc);
                        uploadPhotoScreen.addActionListener(this);
                    }
                    UiApplication.getUiApplication().pushScreen(uploadPhotoScreen);

                } else if (event.getAction().equals(FriendsListScreen.ACTION_ENTER)) {
                    if (friendsListScreen == null) {
                        friendsListScreen = new FriendsListScreen(fbc);
                        friendsListScreen.addActionListener(this);
                    }
                    friendsListScreen.loadList();
                    UiApplication.getUiApplication().pushScreen(friendsListScreen);

                } else if (event.getAction().equals(PokeFriendScreen.ACTION_ENTER)) {
                    if (pokeFriendScreen == null) {
                        pokeFriendScreen = new PokeFriendScreen(fbc);
                        pokeFriendScreen.addActionListener(this);
                    }
                    UiApplication.getUiApplication().pushScreen(pokeFriendScreen);

                } else if (event.getAction().equals(PostWallScreen.ACTION_ENTER)) {
                    if (postWallScreen == null) {
                        postWallScreen = new PostWallScreen(fbc);
                        postWallScreen.addActionListener(this);
                    }
                    postWallScreen.loadList();
                    UiApplication.getUiApplication().pushScreen(postWallScreen);

                } else if (event.getAction().equals(SendMessageScreen.ACTION_ENTER)) {
                    if (sendMessageScreen == null) {
                        sendMessageScreen = new SendMessageScreen(fbc);
                        sendMessageScreen.addActionListener(this);
                    }
                    UiApplication.getUiApplication().pushScreen(sendMessageScreen);
                }

            } else if (event.getSource() == updateStatusScreen) {
                if (event.getAction().equals(UpdateStatusScreen.ACTION_SUCCESS)) {
                    Dialog.inform("Status updated");

                    try {
                        UiApplication.getUiApplication().popScreen(updateStatusScreen);
                    } catch (IllegalArgumentException e) {
                    }

                } else if (event.getAction().equals(UpdateStatusScreen.ACTION_SUCCESS)) {
                    Dialog.alert("Error: " + event.getData());
                }

            } else if (event.getSource() == recentUpdatesScreen) {
                if (event.getAction().equals(RecentUpdatesScreen.ACTION_SUCCESS)) {
                    try {
                        UiApplication.getUiApplication().popScreen(recentUpdatesScreen);
                    } catch (IllegalArgumentException e) {
                    }
                } else if (event.getAction().equals(RecentUpdatesScreen.ACTION_ERROR)) {
                    Dialog.alert("Error: " + event.getData());
                }
            } else if (event.getSource() == uploadPhotoScreen) {
                if (event.getAction().equals(UploadPhotoScreen.ACTION_SUCCESS)) {
                    try {
                        UiApplication.getUiApplication().popScreen(uploadPhotoScreen);
                    } catch (IllegalArgumentException e) {
                    }
                } else if (event.getAction().equals(UploadPhotoScreen.ACTION_ERROR)) {
                    Dialog.alert("Error: " + event.getData());
                }
            } else if (event.getSource() == friendsListScreen) {
                if (event.getAction().equals(FriendsListScreen.ACTION_SUCCESS)) {
                    try {
                        UiApplication.getUiApplication().popScreen(friendsListScreen);
                    } catch (IllegalArgumentException e) {
                    }
                } else if (event.getAction().equals(FriendsListScreen.ACTION_ERROR)) {
                    Dialog.alert("Error: " + event.getData());
                }
            } else if (event.getSource() == pokeFriendScreen) {
                if (event.getAction().equals(PokeFriendScreen.ACTION_SUCCESS)) {
                    try {
                        UiApplication.getUiApplication().popScreen(pokeFriendScreen);
                    } catch (IllegalArgumentException e) {
                    }
                } else if (event.getAction().equals(PokeFriendScreen.ACTION_ERROR)) {
                    Dialog.alert("Error: " + event.getData());
                }
            } else if (event.getSource() == postWallScreen) {
                if (event.getAction().equals(PostWallScreen.ACTION_SUCCESS)) {
                    Dialog.inform("Wall posted");

                    try {
                        UiApplication.getUiApplication().popScreen(postWallScreen);
                    } catch (IllegalArgumentException e) {
                    }
                } else if (event.getAction().equals(PostWallScreen.ACTION_ERROR)) {
                    Dialog.alert("Error: " + event.getData());
                }
            } else if (event.getSource() == sendMessageScreen) {
                if (event.getAction().equals(SendMessageScreen.ACTION_SUCCESS)) {
                    try {
                        UiApplication.getUiApplication().popScreen(sendMessageScreen);
                    } catch (IllegalArgumentException e) {
                    }
                } else if (event.getAction().equals(SendMessageScreen.ACTION_ERROR)) {
                    Dialog.alert("Error: " + event.getData());
                }
            }
         */}
    }

資格情報をクリアするための以下のコード

public void logoutAndExit() {
        saveContext(null);
        logoutScreen = new LogoutScreen(fbc);
        logoutScreen.addActionListener(this);
    }
4

0 に答える 0