在Android中使用Facebook SDK,requestNewPublishPermissions始终拒绝我的publish_actions权限

时间:2014-09-12 13:20:53

标签: android facebook-login facebook-android-sdk android-facebook android-sharing

我正在尝试通过Facebook SDK分享来自Android的照片,但是当我尝试请求已打开会话的publish_actions权限时,Facebook会以拒绝权限返回,而不显示屏幕,询问您是否代表您发布。这是为什么?我该如何解决? 顺便说一句,我没有在Log中收到任何错误或错误。

这是我的代码:

private static final List<String> PERMISSIONS = Arrays.asList("publish_actions");
public void onShareFacebook() {
    progressDialog.show();
    Session session = Session.getActiveSession();
    if (session == null || !session.isOpened()){
        LoginButton loginFacebookButton = new LoginButton(this);
        loginFacebookButton.setPublishPermissions(PERMISSIONS);
        loginFacebookButton.performClick();
        pendingShare = true;
    }
    else if (session != null && session.isOpened()){
        facebookSharePhoto();
    }
}

private void onSessionStateChange(Session session, SessionState state, Exception exception) {
    if (state.isOpened()) {
        if (pendingPublishReauthorization && 
                state.equals(SessionState.OPENED_TOKEN_UPDATED)) {
            pendingPublishReauthorization = false;
            onShareFacebook();
        }
        else if (pendingShare){
            onShareFacebook();
        }
    } 
}

private void facebookSharePhoto(){
    pendingShare = false;

    Bitmap screenshotImage = takeScreenShot();
    String message = invokeEvent.name;

    postPhoto(screenshotImage, message, callbackShareFacebook);
}

private void postPhoto(Bitmap image, String message, Request.Callback callback) {
    Session session = Session.getActiveSession();

    if (session != null){

        // Check for publish permissions    
        List<String> permissions = session.getPermissions();
        List<String> permissionsd = session.getDeclinedPermissions();
        if (isSubsetOf(permissionsd, PERMISSIONS)){
            Toast.makeText(this, "Permisos denegados", Toast.LENGTH_SHORT).show();
            onBackPressed();
            return;
        }
        if (!isSubsetOf(PERMISSIONS, permissions)) {
            pendingPublishReauthorization = true;
            Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS);
            session.requestNewPublishPermissions(newPermissionsRequest);
            return;
        }

        Bundle postParams = new Bundle();
        postParams.putString("name", message);


        Log.d(TAG, "inicio getImageAsData");
        postParams.putByteArray("picture", getImageAsData(image));
        Log.d(TAG, "fin getImageAsData");

        Request request = new Request(session, "me/photos", postParams, HttpMethod.POST, callback);
        Request.executeBatchAsync(request);

    }

}

在开始时我打电话给函数:

            session.requestNewPublishPermissions(newPermissionsRequest);

但是当回调回来时,会话有&#34; publish_actions&#34;在这里拒绝许可:

        List<String> permissionsd = session.getDeclinedPermissions();
        if (isSubsetOf(permissionsd, PERMISSIONS)){
            Toast.makeText(this, "Permisos denegados", Toast.LENGTH_SHORT).show();
            onBackPressed();
            return;
        }

1 个答案:

答案 0 :(得分:0)

我注意到当我使用在Facebook上创建应用程序的帐户登录Facebook时,不会发生这种情况。这意味着,如果我不是Facebook应用程序的开发人员/测试人员,则不会出现要求发布权限的弹出窗口。

如果您激活“公众可用”的切换按钮,则无关紧要。在您提交Facebook申请以供审核之前,该应用程序将无法向公众开放(“开始提交”按钮)。

我提到的两个按钮的屏幕截图: enter image description here

解决方案: 为您的应用启动提交,或将Facebook帐户添加到您应用的测试者角色。