0
 01-29 21:06:00.601: ERROR/AndroidRuntime(582): FATAL EXCEPTION: main
     java.lang.IllegalStateException: Could not execute method of the activity
     at android.view.View$1.onClick(View.java:2144)
     at android.view.View.performClick(View.java:2485)
     at android.view.View$PerformClick.run(View.java:9080)
     at android.os.Handler.handleCallback(Handler.java:587)
     at android.os.Handler.dispatchMessage(Handler.java:92)
     at android.os.Looper.loop(Looper.java:130)
     at android.app.ActivityThread.main(ActivityThread.java:3687)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:507)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
     at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.reflect.InvocationTargetException
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:507)
     at android.view.View$1.onClick(View.java:2139)
     ... 11 more
     Caused by: java.lang.UnsupportedOperationException: Session: an attempt was made to request new permissions for a session that is not currently open.
     at com.facebook.Session.requestNewPermissions(Session.java:977)
     at com.facebook.Session.requestNewPublishPermissions(Session.java:501)
     at ***.MainActivity.postToFacebook(MainActivity.java:105)
     ... 14 more

异常在行中抛出

 session.requestNewPublishPermissions(newPermissionsRequest);
 // Check for publish permissions
            List<String> permissions = session.getPermissions();
            if (!isSubsetOf(PERMISSIONS, permissions)) {
                pendingPublishReauthorization = true;
                Session.NewPermissionsRequest newPermissionsRequest = new Session
                        .NewPermissionsRequest(this, PERMISSIONS);


                session.requestNewPublishPermissions(newPermissionsRequest);


                Toast.makeText(getActivity().getApplicationContext(),
                        "Not enough permissions",
                        Toast.LENGTH_SHORT).show();
                return;
            }

这个异常是什么意思以及如何解决它?

4

3 回答 3

1

Dmytro,根据我的评论,我整理了几篇文章,充分解释了打开 Facebook 会话并请求额外权限:这里这里。希望您和其他人发现它有益并节省开始使用 SDK 的时间!:)

编辑:您收到此异常的原因是您无法在未打开的会话上请求新权限。您需要在请求新权限或发出其他 Facebook API 请求之前打开会话。我在上面链接的文章中整理了一个指南,确保在用户会话打开并且用户拥有所需权限之前不会发出 Facebook API 请求(例如发布到用户的提要等)。

于 2013-02-28T21:50:11.833 回答
0

这意味着您请求权限的会话处于非活动状态/已过期。您需要重新建立会话才能请求权限。

于 2013-01-29T19:25:29.943 回答
0

在调用 requestNewPublishPermissions 之前,您是否调用过 session.openForPublish(Session.OpenRequest openRequest)?

于 2013-01-29T19:28:48.437 回答