3

我已将 Facebook 集成到我的应用程序中并尝试分享一些内容。当我调用 FaceBookMain() 时,它显示如下错误:“成功安全警告:请将上面的 URL 视为您的密码,不要与任何人分享。 ”有时在浏览器(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

不要使用安全连接。使用 http而不是 https。

你可以参考 这里

stackoverflow中也出现了同样的问题

脸书警告

于 2014-10-14T09:44:57.760 回答