这是我的代码
private void postToWall(String msg) {
Bundle parameters = new Bundle();
JSONObject attachment = new JSONObject();
String myjosn="{\"name\":\"LangGuage\",\"href\":\"http://www.hunkatech.com\",\"caption\":\" \",\"description\":\""+messageToPost+"\",\"media\":[{\"type\":\"image\",\"src\":\"http://hwsdemos.com/LangGuage/medal_1.png\",\"href\":\"http://www.hunkatech.com\"}],\"properties\":{\"Powered by:\":{\"text\":\"Hunka Technology Pvt. Ltd.\",\"href\":\"http://www.hunkatech.com\"}}}";
try {
parameters.putString(Facebook.TOKEN, facebook.getAccessToken());
parameters.putString("attachment",myjosn.toString());
String response = facebook.request("me/feed", parameters, "POST");
System.out.println("----responce" + response);
if (response.contains("Duplicate status message")) {
progressHandler.sendEmptyMessage(1);
resp = 1;
} else if (response == null || response.equals("")
|| response.equals("false") || response.contains("error")) {
Log.d("error", "error response");
} else {
progressHandler.sendEmptyMessage(0);
resp = 0;
}
} catch (Exception e) {
Log.e(TAG, "Posting fail");
e.printStackTrace();
}
}
我想在Facebook上发布带有图片的消息。我的json是正确的我已经在json格式化程序编辑器上检查了它。我得到了以下异常。需要建议如何解决它。
更新:借助以下代码发布了我的消息和图片:
parameters.putString("link", "http://www.hunkatech.com");
parameters.putString("picture", "http://hwsdemos.com/LangGuage/medal_1.png");
parameters.putString("name", "LangGuage");// name of link
parameters.putString("captions", "hello");
parameters.putString("message", "This is my message!!");
但是我希望将图像保留给文本,但是上面的代码将结果显示为Imgae以下消息。 更新:我无法发布任何形式json.can任何人请解决这个问题我想发送附件绑定图像和massege与json。
答案 0 :(得分:2)
您可以尝试另外添加此参数:
parameters.putString("message", "this is my message");
编辑:
你可以尝试:
parameters.putString("link", "http://www.hunkatech.com");
parameters.putString("picture", "http://hwsdemos.com/LangGuage/medal_1.png");
parameters.putString("name", "LangGuage");// name of link
parameters.putString("captions", "hello");
parameters.putString("message", "This is my message!!");
答案 1 :(得分:1)
我是怎么做到的。
private void publishFeedDialog() {
System.out.println("Working");
Bundle postParams = new Bundle();
postParams.putString("name", "I am an Engineer");
postParams.putString("caption",
"Working very heard to make things work.");
postParams
.putString("description",
"This project is killing me, Still I am trying, and finally I got success.");
postParams.putString("link", "http://www.kodebusters.com");
postParams
.putString(
"picture",
"http://cdn1.iconfinder.com/data/icons/iconslandsport/PNG/128x128/Soccer_Ball.png");
new MYasync(postParams).execute();
}
在AsyncTask上运行网络调用,或者可以通过异常
运行 class MYasync extends AsyncTask<Void, Void, Void> {
Bundle params;
private String res;
public MYasync(Bundle params) {
super();
this.params = params;
}
@Override
protected void onPostExecute(Void result) {
System.out.println(res);
super.onPostExecute(result);
}
@Override
protected Void doInBackground(Void... pp) {
try {
res = facebook.request("me/feed", params, "POST");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}