您可以通过使用图形 api 来简单地做到这一点。你要做的是
1) 获取好友列表(带有姓名和 Facebook ID)
2) 使用图形 api 和“FriendID/feed”作为图形 URL 发出“POST”请求
以下是我的代码。在使用我的代码之前,您应该尝试更多地了解图形 api 和 JSONObject。
1) 获取好友列表
public JSONArray GetFriendList(){
Bundle params = new Bundle();
String resp="";
JSONArray resp_json=null;
try {
resp = fb.request("me/friends", params, "GET");
resp_json=new JSONArray(resp);
} catch (FileNotFoundException e) {
//...
} catch (MalformedURLException e) {
//...
} catch (IOException e) {
//...
}catch(JSONException e){
//...
}
return resp_json;//JSONArray of friend list, try to use debug mode to browse the content and parse it yourself,get a JSONObject from the JSONArray and get the user ID of that JSONObject
};
2) 贴朋友墙
public String PostWall(String Message,int Level,String FriendID){
//FriendID can be grepped form the function above
|/*REMARK:Privacy Level
* level 0 ==>only me
* level 1==>friend only
* level 2==>public
*/
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());
String resp= "";
try {
resp = fb.request(FriendID+"/feed", params, "POST");
} catch (FileNotFoundException e) {
} catch (MalformedURLException e) {
} catch (IOException e) {
}
try{
resp = new JSONObject(resp).getString("id");
return resp;//The post ID
}catch(JSONException e1){
//
}
};