我正在做一个示例Facebook应用程序,因为我必须将文件发布给朋友列表中的某个朋友不发布,而不是在我的墙上发布它必须只对特定的人可见,我使用以下代码,它在默认的Facebook Utll类上给出错误和异常。我在这里发布我的代码,如果有可能纠正其他提供一个很好的解决方案...在此先感谢....
Bundle params = new Bundle();
params=getIntent().getExtras();
String new_data= params.getString("new_frdId");
params.putString("method", "publish_stream");
params.putString("access_token", UI_Friend_Finder.accesstoken);
params
.putString(
"attachment",
"{\"name\":\""
+ "\",\"href\":\"http://www.google.co.in"
+ "\",\"description\":\"
+ "\",\"media\":[{\"type\":\"image\",\"src\":\""
+ ""
+ "\",\"href\":\""
+ "\"}]}");
authenticatedFacebook.dialog(PostToFriend.this, "stream_publish",
params, new TestUiServerListener());
finish();
}
});
}
class TestUiServerListener implements DialogListener {
public void onComplete(Bundle values) {
final String postId = values.getString("post_id");
if (postId != null) {
new AsyncFacebookRunner(authenticatedFacebook).request(postId,
new TestPostRequestListener());
} else {
PostToFriend.this.runOnUiThread(new Runnable() {
public void run() {
}
});
}
}
public void onCancel() {
}
public void onError(DialogError e) {
e.printStackTrace();
}
public void onFacebookError(FacebookError e) {
e.printStackTrace();
}
}
public class TestPostRequestListener implements RequestListener {
public void onComplete(final String response, final Object state) {
try {
JSONObject json = Util.parseJson(response);
String postId = json.getString("id");
PostToFriend.this.runOnUiThread(new Runnable() {
public void run() {
Log.d("Tests", "Testing wall post success");
}
});
} catch (Throwable e) {
}
}
public void onFacebookError(FacebookError e, final Object state) {
e.printStackTrace();
}
public void onFileNotFoundException(FileNotFoundException e,
final Object state) {
e.printStackTrace();
}
public void onIOException(IOException e, final Object state) {
e.printStackTrace();
}
public void onMalformedURLException(MalformedURLException e,
final Object state) {
e.printStackTrace();
}
}
public class TestLoginListener implements DialogListener {
public void onComplete(Bundle values) {
if (authenticatedFacebook.isSessionValid() == true) {
String response = null;
JSONObject jObject = null;
try {
jObject = new JSONObject(
authenticatedFacebook.request("me"));
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
editor.commit();
finish();
}
}
public void onCancel() {
}
public void onError(DialogError e) {
e.printStackTrace();
}
public void onFacebookError(FacebookError e) {
e.printStackTrace();
}
}
答案 0 :(得分:0)
这是code..i将stream.publish方法放在请求函数中..它运行良好..
protected void postToWall(String temp2) {
System.out.println("<<inside the post method>>");
Bundle params = new Bundle();
params.putString("message", _messageInput.getText().toString()"some text Here);
params.putString("caption", "{*actor*} just posted a secret message.");
params.putString("description","A secret message is waiting for you. Click the link to decode it.");
params.putString("name", "A Secret Message For You");
params.putString("picture","http://www.kxminteractive.com/Content/images/app_logos/secretMessage.png");
params.putString("link", "http://www.kxminteractive.com/decrypt/");
**mAsyncRunner.request(((temp2 == null) ? "me" : temp2) + "/feed",
params, "POST", new WallPostRequestListener(),stream.publish);**
}