3

アプリに Facebook を統合し、いくつかのコンテンツを共有しようとしています。FaceBookMain () を呼び出すと、次のようなエラーが表示されます。このエラーは、ブラウザ (Webview) で Facebook にログインした後に発生する場合があります。それ以外の場合は、共有ボタンをクリックした直後に発生します。

ここで最も重要なことは、シミュレーターでこの問題に直面していないことです。Facebook との共有は、シミュレーターでは正しく機能していますが、デバイスでは機能していません。

それにいくつかのクラスファイルを追加しています:

FacebookMain.java クラスは次のとおりです。

import net.rim.device.api.applicationcontrol.ApplicationPermissions;
import net.rim.device.api.applicationcontrol.ApplicationPermissionsManager;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;
import net.rim.device.api.ui.UiApplication;

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 = "406758776102494";//"533918076671162" ;
    private final static long persistentObjectId = 0x854d1b7fa43e3577L;

    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 static boolean isFacebookScreen = false;

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

        checkPermissions();

        fbc=new FacebookContext(NEXT_URL, APPLICATION_ID);
        loginScreen = new LoginScreen(fbc,"KingdomConnect: "+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);*/
        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);

        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) {}
}

Facebook.java クラスです。

   public class Facebook {

        protected Logger log = Logger.getLogger(getClass());
        public static String API_URL = "https://graph.facebook.com";

        public Facebook() {
        }

        public static Object read(String path, String accessToken) throws FacebookException {
            return read(path, null, accessToken);
        }

        public static Object read(String path, Parameters params, String accessToken) throws FacebookException {
            Hashtable args = new Hashtable();
            args.put("access_token", accessToken);
            args.put("format", "JSON");

            if ((params != null) && (params.getCount() > 0)) {
                Enumeration paramNamesEnum = params.getParameterNames();

                while (paramNamesEnum.hasMoreElements()) {
                    String paramName = (String) paramNamesEnum.nextElement();
                    String paramValue = params.get(paramName).getValue();
                    args.put(paramName, paramValue);
                }
            }

            try {
                StringBuffer responseBuffer = HttpClient.getInstance().doGet(API_URL + '/' + path, args);

                if (responseBuffer.length() == 0) {
                    throw new Exception("Empty response");
                }

                return new JSONObject(new JSONTokener(responseBuffer.toString()));

            } catch (Throwable t) {
                t.printStackTrace();
                throw new FacebookException(t.getMessage());
            }
        }

        public static Object write(String path, Object object, String accessToken) throws FacebookException {
            Hashtable data = new Hashtable();
            data.put("access_token", accessToken);
            data.put("format", "JSON");

            try {
                JSONObject jsonObject = (JSONObject) object;
                Enumeration keysEnum = jsonObject.keys();

                while (keysEnum.hasMoreElements()) {
                    String key = (String) keysEnum.nextElement();
                    Object val = jsonObject.get(key);

                    if (!(val instanceof JSONObject)) {
                        data.put(key, val.toString());
                    }
                }

                StringBuffer responseBuffer = HttpClient.getInstance().doPost(API_URL + '/' + path, data);

                if (responseBuffer.length() == 0) {
                    throw new FacebookException("Empty response");
                }

                return new JSONObject(new JSONTokener(responseBuffer.toString()));
            } catch (Exception e) {
                throw new FacebookException(e.getMessage());
            }
        }

        public static Object delete(String path, String accessToken) throws FacebookException {
            Hashtable data = new Hashtable();
            data.put("access_token", accessToken);
            data.put("format", "JSON");
            data.put("method", "delete");

            try {
                StringBuffer responseBuffer = HttpClient.getInstance().doPost(API_URL + '/' + path, data);

                if (responseBuffer.length() == 0) {
                    throw new FacebookException("Empty response");
                }

                return new JSONObject(new JSONTokener(responseBuffer.toString()));
            } catch (Exception e) {
                throw new FacebookException(e.getMessage());
            }
        }

    }


And it is BrowserScreen.class:

public class BrowserScreen extends ActionScreen {

    //  int[] preferredTransportTypes = { TransportInfo.TRANSPORT_TCP_CELLULAR, TransportInfo.TRANSPORT_WAP2, TransportInfo.TRANSPORT_BIS_B };
    int[] preferredTransportTypes = TransportInfo.getAvailableTransportTypes();//{ TransportInfo.TRANSPORT_BIS_B };
    ConnectionFactory cf;
    BrowserFieldConfig bfc;
    BrowserField bf;
    String url;

    public BrowserScreen(String pUrl) {
        super();
        url = pUrl;

        cf = new ConnectionFactory();
        cf.setPreferredTransportTypes(preferredTransportTypes);

        bfc = new BrowserFieldConfig();
        bfc.setProperty(BrowserFieldConfig.ALLOW_CS_XHR, Boolean.TRUE);
        bfc.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE);
        bfc.setProperty(BrowserFieldConfig.USER_SCALABLE, Boolean.TRUE);
        bfc.setProperty(BrowserFieldConfig.MDS_TRANSCODING_ENABLED, Boolean.FALSE);
        bfc.setProperty(BrowserFieldConfig.NAVIGATION_MODE, BrowserFieldConfig.NAVIGATION_MODE_POINTER);
        bfc.setProperty(BrowserFieldConfig.VIEWPORT_WIDTH, new Integer(Display.getWidth()));
        //      bfc.setProperty(BrowserFieldConfig.CONNECTION_FACTORY, cf);

        bf = new BrowserField(bfc);

    }

    public void browse() {
        show();
        fetch();
    }

    public void show() {
        add(bf);
    }

    public void fetch() {
        bf.requestContent(url);
    }

    public void hide() {
        delete(bf);
    }

}

何か手がかりがある場合、またはそれを取得するための関連コードが必要な場合は、お知らせください。

4

1 に答える 1

0

安全な接続を使用しないでください。https の代わりにhttp を使用します。

ここで参照でき ます

同じ問題がstackoverflowに表示されます

フェイスブックの警告

于 2014-10-14T09:44:57.760 に答える