facebook graph Api, how to set the privacy setting

2020-07-27 03:33发布

问题:

I have a custom dailog with a spinner to choose who can see our post on userwall, i want to choose and post on my wall, but not sure how to put privacy settings in wall and send it.

getId = getfbId(id);

        if (getId != null) {

            String url = Constants.fbindexURL + "lang=" + lang + "&lat=" + lat + "&getfbid=" + getId;
            myplace = Constants.loadedplace.getCityName();
            parameters.putString("name", getString(R.string.reply));
            parameters.putString("caption", fbUuer + " in " + Constants.loadedplace.getCityName());
            parameters.putString("link", url);
            parameters.putString("picture", Constants.ImageURL);    
//------------> parameters.putString("privacy",  );

below is code for getting the values of my spinner

 spinner = (Spinner)dialog.findViewById(R.id.spinner);
             spinner.setOnItemSelectedListener(new Adapter

View.OnItemSelectedListener() {
                    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                        String choose = spinner.getSelectedItem().toString();

                    }
                    public void onNothingSelected(AdapterView<?> parent) {
                    }
                });

can someonesuggest how can i choose who to see from the spinner and post accordingly on my wall. Any help is appreciated

回答1:

Two Facebook documents are of importance here:

  1. https://developers.facebook.com/docs/reference/api/user/ (Scroll down almost to the end of the page to see the POSTS - Create section.)
  2. https://developers.facebook.com/docs/reference/api/privacy-parameter/

A point of importance here is, you can only choose a different Privacy Setting for posts on your own wall. Even more important is that a user must select the privacy proactively himself. You cannot override the settings that the user has selected as default when he selected the permission for your app the first time. (The ones available in their account settings)

To change the privacy of an individual post, for example, if you need to make a Post available only to you, you will need to include this in your parameters:

NOTE: The privacy settings have to be in a JSON object.

privacy={'value':'SELF'}

Usage example:

JSONObject jsonObject = new JSONObject();
jsonObject.put("value", "SELF");
parameters.putString("privacy", jsonObject.toString());

The second link mentioned above has more details which will be of use. Do read them all for better configuring your app.

Suggestion: For selecting friends on FB that you wish to allow the post to be visible, you can use this example here for selecting multiple users from a GridView: http://vikaskanani.wordpress.com/2011/07/20/android-custom-image-gallery-with-checkbox-in-grid-to-select-multiple/