Question

I have searched through many threads and i was not successful yet

I am following https://developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/ and i have successfully integrated the native FB to my app . I could retrieve the FB Friends list and post to the wall . . . .

But i am searching how to set the privacy settings for the activities i post .

From the app, i want to ask the user for the privacy settings and accordingly i want to set the privacy either to ONLY_ME / FRIENDS / EVERYONE

I have tried

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

but that didn't work, then i tried editing the Login Properties in LoginButton.class of FB . I just hardcoded it to just test

private SessionDefaultAudience defaultAudience = SessionDefaultAudience.ONLY_ME;

but even this didn't work and then i tried with the following code referring on of the threadss but i was still not successful

private void requestPublishPermissions(Session session)
    {
        Log.e("session.getPermissions().contains(publish_actions)", " is "+session.getPermissions().contains("publish_actions"));
        if (session != null && session.getPermissions().contains("publish_actions")) 
        {
            Log.e(" inside if loop ", " session.getPermissions().contains(publish_actions) ");
            Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(SplashScreen.this, Arrays.asList("publish_actions"))
            // demonstrate how to set an audience for the publish permissions,
            // if none are set, this defaults to FRIENDS
            .setDefaultAudience(SessionDefaultAudience.ONLY_ME);
            session.requestNewPublishPermissions(newPermissionsRequest);
        }
    }

I don't know where i am going wrong. Please advice, thanks in advance .

Was it helpful?

Solution

The setDefaultAudience is only useful the first time you request publish permissions. It basically sets a global ceiling for your app (it means your app cannot post above that privacy level). The user can also go into their settings, and change that ceiling at any time (unbeknownst to the app), so even if you asked for FRIENDS, they might later change it to ONLY_ME.

If you want to adjust the privacy level at runtime, you can set the "privacy" field when posting to me/feed. The valid inputs to the privacy field are defined here. Just be aware that no matter what you put as the privacy, it cannot go above what the user has set for your app.

Alternatively, you can use the native share dialog, which allows the user to control privacy, message, etc, and doesn't not require any login (or publish permissions) since it delegates to the Facebook app.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top