Android应用程序:向用户发送帖子';s的朋友,但事先不知道其id
我希望我的应用程序能够向朋友的facebook墙发送一些文字。 这是我到目前为止得到的Android应用程序:向用户发送帖子';s的朋友,但事先不知道其id,android,facebook,sendmessage,Android,Facebook,Sendmessage,我希望我的应用程序能够向朋友的facebook墙发送一些文字。 这是我到目前为止得到的 private void postOnFriendsWall() { Bundle params = new Bundle(); params.putString("to", ""); facebook.dialog(this, "feed", params, new DialogListener() 它使我能够向自己的墙发送
private void postOnFriendsWall() {
Bundle params = new Bundle();
params.putString("to", "");
facebook.dialog(this, "feed", params, new DialogListener()
它使我能够向自己的墙发送消息。
我试图通过让id参数为空来显示所有的朋友,但它不起作用,它只允许我在自己的墙上张贴。是否有一个facebook对话框,用户可以在其中选择要向谁发送消息
我也看到过其他答案,这些答案很容易做到,但前提是你事先知道朋友的ID。
我不知道我的应用程序用户的朋友id,所以如何动态获取列表
编辑:我想如果我描述了我想要的流程,我的问题会更清楚:
您可以通过使用GraphAPI简单地实现这一点。 你要做的是 1) 获取好友列表(带有姓名和facebook ID) 2) 使用图形api和“FriendID/feed”作为图形URL发出“POST”请求
下面是我的代码。在使用我的代码之前,您应该尝试更多地了解graph 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){
//
}
};
您可以通过使用GraphAPI简单地实现这一点。 你要做的是 1) 获取好友列表(带有姓名和facebook ID) 2) 使用图形api和“FriendID/feed”作为图形URL发出“POST”请求
下面是我的代码。在使用我的代码之前,您应该尝试更多地了解graph 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){
//
}
};
我怀疑这是否可能。我曾经尝试过这个,但失败了。嘿,谜,谢谢你的投入,我做了很多研究,确实没有什么可以做的。不过,我不明白为什么这是不可能的。你知道这是否是Facebook的政策吗?我怀疑这是否可能。我曾经尝试过这个,但失败了。嘿,谜,谢谢你的投入,我做了很多研究,确实没有什么可以做的。不过,我不明白为什么这是不可能的。你知道这是否是Facebook的政策问题吗?谢谢你的帮助,你有如何实现这一点的教程吗?请提供一些代码和更多详细信息。通过学习facebook android sdk中的简单示例,尝试学习如何使用graph api。请随意接受我的答案。谢谢,伙计,我现在没有时间来测试它,但这绝对是我可以从你开始的事情。你应该意识到这种能力很快就会消失,看到了吗。。“我们将删除通过Graph API发布到用户朋友墙的功能。如果您希望允许用户发布到朋友的时间线,请调用“订阅源”对话框。“感谢您的帮助,您有如何实现此目的的教程吗?”?请提供一些代码和更多详细信息。通过学习facebook android sdk中的简单示例,尝试学习如何使用graph api。请随意接受我的答案。谢谢,伙计,我现在没有时间来测试它,但这绝对是我可以从你开始的事情。你应该意识到这种能力很快就会消失,看到了吗。。“我们将删除通过Graph API发布到用户朋友墙的功能。如果您想允许人们发布到朋友的时间线,请调用提要对话框。”