简体   繁体   English

Android Facebook SDK,请求发布权限“ manage_pages”未更新会话权限列表

[英]Android Facebook SDK, requesting publish permission “manage_pages” isn't updating session permissions list

I am using Parse and Facebook SDKs on Android. 我正在Android上使用Parse和Facebook SDK。 I'm trying to request for the permission "manage_pages" after the facebook account is linked. 我正在尝试链接Facebook帐户后请求权限“ manage_pages”。 But whenever I make the request it does NOT add to the list of permissions in Session.getPermissions() . 但是,每当我发出请求时,它都不会添加到Session.getPermissions()中的权限列表中。 However, the Facebook dialog popup asking for the "manage_pages" permission appears, and it is listed in my Facebook Apps settings on facebook.com. 但是,将出现要求“ manage_pages”权限的Facebook对话框弹出窗口,该对话框在我在facebook.com上的Facebook Apps设置中列出。

In MainActivity: 在MainActivity中:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.e(TAG, "Receiving activity result with requestCode: " + requestCode + " resultcode: " + resultCode);
    if (requestCode == 32665) // Code for when facebook is NOT linked
        ParseFacebookUtils.finishAuthentication(requestCode, resultCode,
                data);
    super.onActivityResult(requestCode, resultCode, data);
    Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}

In FacebookFragment's onCreateView() : 在FacebookFragment的onCreateView()

        connectBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (user == null) {
                    Log.d(TAG, "User is null.");
                    return;
                }
                if (!ParseFacebookUtils.isLinked(user)) {
                    ParseFacebookUtils.link(user,
                            FacebookFragment.this.getActivity(),
                            new SaveCallback() {
                                @Override
                                public void done(ParseException ex) {
                                    if (ParseFacebookUtils.isLinked(user)) {
                                        Log.d(TAG,
                                                "Woohoo, user logged in with Facebook!");
                                        user.add(ParseConstants.USER_ARRAY_NETWORKS, ParseConstants.NETWORK_CODE_FACEBOOK);
                                        user.saveInBackground();

                                        Session session = Session.getActiveSession();
                                        // Check for publish permissions
                                        List<String> permissions = session.getPermissions();
                                        if (!permissions
                                                .contains(Permissions.Page.MANAGE_PAGES)) {
                                            Log.e(TAG, "We don't have hte permission: " + Permissions.Page.MANAGE_PAGES + "... we have " + Arrays.toString(permissions.toArray()));
                                            Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(
                                                    getActivity(),
                                                    "manage_pages");
                                            newPermissionsRequest.setRequestCode(23232);
                                            newPermissionsRequest.setCallback(new StatusCallback() {

                                                @Override
                                                public void call(
                                                        Session session,
                                                        SessionState state,
                                                        Exception exception) {
                                                    List<String> permissions = session.getPermissions();

                                                    Log.e(TAG, "CALLBACK Permissions: " + Arrays.toString(permissions.toArray()));
                                                    if (exception != null)
                                                        Log.e(TAG, "EXCEPTION: " + exception.getMessage());
                                                }

                                            });
                                            session.requestNewPublishPermissions(newPermissionsRequest);
//                                          ParseFacebookUtils.saveLatestSessionData(ParseUser.getCurrentUser());
                                        }

                                        showMessages();
                                    } else {
                                        Log.e(TAG, "Uhh user is not linked");
                                    }
                                }
                            });
                } else
                    Log.e(TAG, "User is already linked!");
            }
        });

FacebookFragment's onStart : FacebookFragment的onStart

@Override
public void onStart() {
    super.onStart();
    if (ParseFacebookUtils.isLinked(user)) {
        showMessages();


        Session session = ParseFacebookUtils.getSession();
        // Check for publish permissions
        List<String> permissions = session.getPermissions();

        Log.e(TAG, "Permissions: " + Arrays.toString(permissions.toArray()));
        Log.e(TAG, "Permissions: " + Arrays.toString(Session.getActiveSession().getPermissions().toArray()));

    }
}

This is what appears in logCat: 这是出现在logCat中的内容:

 05-20 15:55:53.077: E/FacebookFragment(1887): We don't have hte permission: manage_pages... we have [public_profile] 05-20 15:55:53.337: E/FacebookFragment(1887): CALLBACK Permissions: [] 05-20 15:55:54.228: E/MainActivity(1887): Receiving activity result with requestCode: 23232 resultcode: -1 05-20 15:55:54.228: E/FacebookFragment(1887): Permissions: [public_profile] 05-20 15:55:54.228: E/FacebookFragment(1887): Permissions: [public_profile] 

I have the same issue as you, unfortunately the Sessions.getPermissions() is pretty useless, you have to logout and login again in the app for the session object to be updated. 我和您有同样的问题,很遗憾,Sessions.getPermissions()毫无用处,您必须注销并再次在应用程序中登录才能更新会话对象。 I tried everything. 我尝试了一切。

What I ended up doing was to totally ditch the session.getPermissions() and just make requests online to the /me/permissions Graph API. 我最终要做的是完全放弃session.getPermissions(),只在线向/ me / permissions Graph API发出请求。

It's the only reliable one that works, without logging in/logging out. 这是唯一无需登录/注销即可运行的可靠设备。

Have you tried the function Session.isPublishPermission("manage_pages") ? 您是否尝试过Session.isPublishPermission("manage_pages")函数? I had the same problem as you, but by using this function, it returned a correct boolean value. 我遇到了与您相同的问题,但是通过使用此函数,它返回了正确的boolean值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM