1

我正在使用以下方法在 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"但它嵌入在 object 中的 graph api。现在我找不到如何在 bundle 中添加这个参数。

这就是 graph api explorer 显示结果的方式。

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

1 回答 1

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();
        }
于 2013-02-25T13:39:38.843 回答