在受限用户可见的Facebook上分享状态

时间:2013-01-29 11:23:03

标签: java android json facebook-graph-api rest

我正在使用以下方法在Facebook上分享状态。

if (facebook.isSessionValid()) {
        Bundle parameters = new Bundle();
        parameters.putString("message", msg);
        try {
            String response = facebook.request("me/feed", parameters,"POST");
            System.out.println(response);
            Toast.makeText(context, "Posted Successfully", Toast.LENGTH_LONG).show();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        login();
    }

我检查过具有参数 allow =“profileid1,profileid2,profileid3”的图形api,但它嵌入在一个对象中。现在我找不到如何在bundle中添加这个参数。

这就是图表api资源管理器显示结果的方式。

    "privacy": {
    "description": "Friends; Except: Artemas Ali, Artemas Ali",
    "value": "CUSTOM",
    "friends": "ALL_FRIENDS",
    "networks": "",
    "allow": "",
    "deny": "1000036022153129,1000017534323389"
  }, 

1 个答案:

答案 0 :(得分:1)

我通过简单地向JSON对象添加值然后转换为字符串以将值传递给API来完成此操作。

 if (facebook.isSessionValid()) {
        Bundle parameters = new Bundle();
        parameters.putString("message", msg);
        if(!customUsers.equals("")){
        JSONObject obj= new JSONObject();

        try {
               obj.put("value", "CUSTOM");
               obj.put("friends", "ALL_FRIENDS");
               try{
                   obj.put("deny", customUsers);   
               }catch(StringIndexOutOfBoundsException ex){
                   Log.d(customUsers, ex.toString());
               }

        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        parameters.putString("privacy", obj.toString());
        }
        try {
            String response = facebook.request("me/feed", parameters,"POST");
            System.out.println(response);
            Toast.makeText(context, "Posted Successfully", Toast.LENGTH_LONG).show();
        } catch (IOException e) {
            e.printStackTrace();
        }