简体   繁体   English

如何在Android中为Facebook设置SessionDefaultAudience

[英]How to set SessionDefaultAudience for facebook in Android

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. 我正在遵循Authenticate-Facebook Developers链接来设置Facebook本机登录名。 I add the following code to SplashFragment.java : 我将以下代码添加到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. 在我的应用程序中,我想提醒用户进入隐私模式( SessionDefaultAudience.EVERYONESessionDefaultAudience.ONLY_MESessionDefaultAudience.FRIENDS )以通过应用程序为其发布设置隐私设置。

I also went through Session.NewPermissionsRequest-Facebook Developers but how to implement this? 我也经历了Session.NewPermissionsRequest-Facebook Developers,但是如何实现呢?

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);

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

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