Java 在facebook上共享状态对有限用户可见
我使用以下方法在facebook上分享状态Java 在facebook上共享状态对有限用户可见,java,android,json,facebook-graph-api,rest,Java,Android,Json,Facebook Graph Api,Rest,我使用以下方法在facebook上分享状态 if (facebook.isSessionValid()) { Bundle parameters = new Bundle(); parameters.putString("message", msg); try { String response = facebook.request("me/feed", parameters,"POST"); Sys
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();
}
我检查了graph api,它有一个参数allow=“profileid1,profileid2,profileid3”,但它嵌入到一个对象中。现在我找不到如何在bundle中添加此参数
这就是graph api explorer显示结果的方式
"privacy": {
"description": "Friends; Except: Artemas Ali, Artemas Ali",
"value": "CUSTOM",
"friends": "ALL_FRIENDS",
"networks": "",
"allow": "",
"deny": "1000036022153129,1000017534323389"
},
我只需将值添加到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();
}
我只需将值添加到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();
}
“但它嵌入到对象中”是什么意思?请再次阅读问题或检查graph api me/feed。您所说的“但它嵌入到对象中”是什么意思?请再次阅读问题或检查graph api me/feed。