添加publish_action权限并在墙上发布

时间:2013-04-14 11:25:58

标签: android facebook

我有一个有两个按钮的活动

  1. 用于登录Facebook。登录后我完成了该活动
  2. 其他按钮用于张贴在墙上
  3. 第一部分我做了Ok但是第二部分我参考了facebook样本,并试图在我的公开会话中添加发布权限,如下所示

    private void performPublish(PendingAction action) {
        Session session = Session.getActiveSession();
        if (session != null) {
            pendingAction = action;
            if (hasPublishPermission()) {
                // We can do the action right away.
                handlePendingAction();
            } else {
                // We need to get new permissions, then complete the action when we get called back.
                session.requestNewPublishPermissions(new Session.NewPermissionsRequest(this, PERMISSIONS));
            }
        }
    }
    

    但我收到以下错误

        04-14 16:49:18.760: E/AndroidRuntime(2529): FATAL EXCEPTION: main
        04-14 16:49:18.760: E/AndroidRuntime(2529): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartcloud/com.smartcloud.HelloFacebookSampleActivity}: java.lang.UnsupportedOperationException: Session: an attempt was made to request new permissions for a session that has a pending request.
        04-14 16:49:18.760: E/AndroidRuntime(2529):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1751)
        04-14 16:49:18.760: E/AndroidRuntime(2529):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1767)
        04-14 16:49:18.760: E/AndroidRuntime(2529):     at android.app.ActivityThread.access$1500(ActivityThread.java:122)
        04-14 16:49:18.760: E/AndroidRuntime(2529):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1005)
        04-14 16:49:18.760: E/AndroidRuntime(2529):     at android.os.Handler.dispatchMessage(Handler.java:99)
        04-14 16:49:18.760: E/AndroidRuntime(2529):     at android.os.Looper.loop(Looper.java:132)
        04-14 16:49:18.760: E/AndroidRuntime(2529):     at android.app.ActivityThread.main(ActivityThread.java:4028)
        04-14 16:49:18.760: E/AndroidRuntime(2529):     at java.lang.reflect.Method.invokeNative(Native Method)
        04-14 16:49:18.760: E/AndroidRuntime(2529):     at java.lang.reflect.Method.invoke(Method.java:491)
        04-14 16:49:18.760: E/AndroidRuntime(2529):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
        04-14 16:49:18.760: E/AndroidRuntime(2529):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
        04-14 16:49:18.760: E/AndroidRuntime(2529):     at dalvik.system.NativeStart.main(Native Method)
        04-14 16:49:18.760: E/AndroidRuntime(2529): Caused by: java.lang.UnsupportedOperationException: Session: an attempt was made to request new permissions for a session that has a pending request.
        04-14 16:49:18.760: E/AndroidRuntime(2529):     at com.facebook.Session.requestNewPermissions(Session.java:968)
        04-14 16:49:18.760: E/AndroidRuntime(2529):     at com.facebook.Session.requestNewPublishPermissions(Session.java:501)
        04-14 16:49:18.760: E/AndroidRuntime(2529):     at com.smartcloud.HelloFacebookSampleActivity.performPublish(HelloFacebookSampleActivity.java:194)
        04-14 16:49:18.760: E/AndroidRuntime(2529):     at com.smartcloud.HelloFacebookSampleActivity.onClickPostStatusUpdate(HelloFacebookSampleActivity.java:161)
        04-14 16:49:18.760: E/AndroidRuntime(2529):     at com.smartcloud.HelloFacebookSampleActivity.onCreate(HelloFacebookSampleActivity.java:89)
        04-14 16:49:18.760: E/AndroidRuntime(2529):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
        04-14 16:49:18.760: E/AndroidRuntime(2529):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1715)
        04-14 16:49:18.760: E/AndroidRuntime(2529):     ... 11 more
    

    请帮帮我!这对我来说非常重要

1 个答案:

答案 0 :(得分:0)

在请求新权限之前,您需要等到session打开。您可以使用statusCallback并检查会话何时打开(在call方法中),之后请求新的权限。