Facebook连接3.5会话:尝试打开已经打开的会话

时间:2014-04-03 10:52:48

标签: android facebook-android-sdk

当我点击下面的fbconnect时:

fbconnect.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // Check for an open session

        /*Session session = Session.getActiveSession();

        if (!session.isOpened() && !session.isClosed()) {
            System.out.println("hereinfb");
            session.openForRead(new Session.OpenRequest(getActivity())
                    .setCallback(callback).setPermissions(
                            Arrays.asList("basic_info", "email",
                                    "user_photos")));
            ;

            fbconnect(session);

        } else {
            System.out.println("hereinfb1");
            Session.openActiveSession(getActivity(), true, callback);

            fbconnect(session);

        }*/


        session = Session.getActiveSession();

        session.openForRead(new Session.OpenRequest(m).setCallback(
                callback).setPermissions(
                Arrays.asList("basic_info", "email", "user_photos")));

        Session.openActiveSession(getActivity(), true, callback);

        System.out.println("fbsession" + session);

        if (session != null) {
            // Get the user's data

            fbconnect(session);

        }

        /*
         * 
         * Session session = Session.getActiveSession();
         * System.out.println("fbsession" + session); if (session !=
         * null) { // Get the user's data fbconnect(session); }else {
         * 
         * fbconnect(session);
         * 
         * }
         */

    }
});

应用程序强制关闭和错误日志显示:

04-03 14:14:14.164: E/AndroidRuntime(29386): FATAL EXCEPTION: main
04-03 14:14:14.164: E/AndroidRuntime(29386): java.lang.UnsupportedOperationException: Session: an attempt was made to open an already opened session.
04-03 14:14:14.164: E/AndroidRuntime(29386):    at com.facebook.Session.open(Session.java:985)
04-03 14:14:14.164: E/AndroidRuntime(29386):    at com.facebook.Session.openForRead(Session.java:388)
04-03 14:14:14.164: E/AndroidRuntime(29386):    at com.orange.re.SlidingMenuFragment$3.onClick(SlidingMenuFragment.java:123)
04-03 14:14:14.164: E/AndroidRuntime(29386):    at android.view.View.performClick(View.java:4475)
04-03 14:14:14.164: E/AndroidRuntime(29386):    at android.view.View$PerformClick.run(View.java:18786)
04-03 14:14:14.164: E/AndroidRuntime(29386):    at android.os.Handler.handleCallback(Handler.java:730)
04-03 14:14:14.164: E/AndroidRuntime(29386):    at android.os.Handler.dispatchMessage(Handler.java:92)
04-03 14:14:14.164: E/AndroidRuntime(29386):    at android.os.Looper.loop(Looper.java:137)
04-03 14:14:14.164: E/AndroidRuntime(29386):    at android.app.ActivityThread.main(ActivityThread.java:5419)
04-03 14:14:14.164: E/AndroidRuntime(29386):    at java.lang.reflect.Method.invokeNative(Native Method)
04-03 14:14:14.164: E/AndroidRuntime(29386):    at java.lang.reflect.Method.invoke(Method.java:525)
04-03 14:14:14.164: E/AndroidRuntime(29386):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
04-03 14:14:14.164: E/AndroidRuntime(29386):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
04-03 14:14:14.164: E/AndroidRuntime(29386):    at dalvik.system.NativeStart.main(Native Method)

此行使应用程序崩溃。

session.openForRead(new Session.OpenRequest(m).setCallback(
                        callback).setPermissions(
                        Arrays.asList("basic_info", "email", "user_photos")));

1 个答案:

答案 0 :(得分:1)

session = Session.getActiveSession();

活动会话已经打开。你不需要打开它。 我就是这样做的:

Session session = Session.getActiveSession();
                    if (session != null && session.isOpened())
                    {

                        List<String> permissions = session.getPermissions();

                        if (!permissions.contains("publish_actions"))
                        {
                            Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(FBLogin.this, Arrays.asList("publish_actions"));

                            session.requestNewPublishPermissions(newPermissionsRequest);
                        }
                }

https://github.com/madhur/MapMyLocation/blob/develop/src/in/co/madhur/mapmylocation/activity/FBLogin.java