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

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

问题描述

我想在 Facebook 上自动发布笔记,并将它们定位到群组中的一个成员.我所说的目标是指只有特定的 Facebook 用户才能阅读笔记.

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.

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

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?

推荐答案

答案在这里.

只需在 JSONObject 格式的 Bundle 中包含privacy",包括值SELF"、ALL_FRIENDS"或EVERYONE".

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

这里使用的是android SDK 2.0,现在已经有3.0了,但是使用graph api的方法是一样的,有问题请留言:)

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 Graph API 时指定隐私的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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