How to set SessionDefaultAudience for facebook in Android

我与影子孤独终老i 提交于 2019-12-11 07:08:03

问题


I have searched a lot for past two days and I was not successful. I am following the Authenticate-Facebook Developers link for setting up the Facebook native login. I add the following code to SplashFragment.java:

authButton = (LoginButton) view.findViewById(R.id.fb_logIn_btn);
authButton.setPublishPermissions(PERMISSION);
authButton.setDefaultAudience(SessionDefaultAudience.ONLY_ME);

But this does not work.

In my app, I want to alert the user to enter the privacy mode(SessionDefaultAudience.EVERYONE or SessionDefaultAudience.ONLY_ME or SessionDefaultAudience.FRIENDS ) to set their privacy setting for their post through the application.

I also went through Session.NewPermissionsRequest-Facebook Developers but how to implement this?


回答1:


You can change the audience and the Permission like that:

private void requestPublishPermissions(Session session) {
    if (session != null && !session.getPermissions().contains("publish_actions")) {
        System.out.println("SEESION Permission");
        Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(mainFragment, Arrays.asList("publish_actions"));
        // demonstrate how to set an audience for the publish permissions,
        // if none are set, this defaults to FRIENDS
          .setDefaultAudience(SessionDefaultAudience.FRIENDS);
        session.requestNewPublishPermissions(newPermissionsRequest);
    }
}

Just change this line to the audience you want

.setDefaultAudience(SessionDefaultAudience.FRIENDS);


来源:https://stackoverflow.com/questions/15738324/how-to-set-sessiondefaultaudience-for-facebook-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!