在Facebook图形API发布时指定隐私 [英] Specify privacy when POSTing to Facebook Graph API

查看:104
本文介绍了在Facebook图形API发布时指定隐私的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Facebook上自动发布Notes,并将其定位到一个组中的单个成员。按目标我的意思是只有一个特定的Facebook用户应该能够阅读该笔记。



有没有办法用图形API?我在旧的REST API中看到,在steam.publish方法中有一个隐私参数(参见 http://developers.facebook.com/docs/reference/rest/stream.publish )。在图API中有一个等价物吗?

解决方案

这是答案。



这是使用Android SDK 2.0,它包含JSONF格式的包,包括SELF,ALL_FRIENDS或EVERYONE ,和3.0现在是可用的,但使用图形API的方式是一样的,留下评论如果你遇到任何问题:)。

  public String PostWall(String Message,int Level){
/ ************************* **********************************
* level 0 ==> only me
* level 1 ==> friend only
* level 2 ==> public
* level> 2 ==> error
********** ******************* /
Bundle params = new Bundle();
params.putString(message,Message);
JSONObject privacy = new JSONObject();
try {
switch(Level){
case 0:
privacy.put(value,SELF);
break;
案例1:
privacy.put(value,ALL_FRIENDS);
break;
case 2:
privacy.put(value,EVERYONE);
break;
}
} catch(JSONException e1){
}
params.putString(privacy,privacy.toString());
//步骤2请求
String resp =;
try {
resp = fb.request(me / feed,params,POST);
} catch(FileNotFoundException e){
} catch(MalformedURLException e){
} catch(IOException e){
}
try {
resp =新的JSONObject(resp).getString(id);
if(enableLog){
Log.d(LOGTAG,***** POSTWALL END *****);
Log.d(LOGTAG,RETURN+ resp);
}
返回
} catch(JSONException e1){
}
}
};


I want to automatically post Notes on Facebook and have them be targeted to just a single member of a group. By target I mean only a specific Facebook user should be able to read the note.

Is there a way to do this with the graph API? I see in the old REST API there is a "privacy" parameter on the steam.publish method (see http://developers.facebook.com/docs/reference/rest/stream.publish). Is there an equivalent in the graph API?

解决方案

Here's the answer.

Just include "privacy" in the Bundle in JSONObject format, including value "SELF", "ALL_FRIENDS" OR "EVERYONE".

This is using android SDK 2.0, and 3.0 is now avaliable, But the way to use graph api is the same, left comment if you reach any problem:).

public String PostWall(String Message,int Level){
    /***********************************************************
        * level 0 ==>only me
        * level 1==>friend only
        * level 2==>public
        * level >2 ==>error
    ***********************************************************/
    Bundle params = new Bundle();
    params.putString("message", Message);
    JSONObject privacy = new JSONObject();
    try {
        switch (Level){
            case 0: 
                privacy.put("value", "SELF");
                break;
            case 1: 
                privacy.put("value", "ALL_FRIENDS");
                break;
            case 2: 
                privacy.put("value", "EVERYONE");
                break;
        }
    } catch (JSONException e1) {
    }
    params.putString("privacy", privacy.toString());
    //Step 2 Request
    String resp= "";
    try {
        resp = fb.request("me/feed", params, "POST");
    } catch (FileNotFoundException e) {
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    }
    try{
        resp = new JSONObject(resp).getString("id");
        if(enableLog){
            Log.d(LOGTAG,"*****POSTWALL END*****");
            Log.d(LOGTAG,"RETURN "+resp);
        }
        return resp;
    }catch(JSONException e1){
    }
}
};

这篇关于在Facebook图形API发布时指定隐私的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆