问题描述
在和本教程我设法将Android应用程序上的Facebook与最新的FacebookSDK集成在一起.我想发布一些内容,因此使用了本教程及其完全正常的工作.我唯一的问题是,我看不到发布"对话框(如本教程中提到的那样),在该对话框中,我希望用户可以修改消息的内容来显示它.我该怎么做?
With help of this post and this tutorial I have managed to integrate Facebook on my Android app with latest FacebookSDK. I want to publish some contents so used the tutorial and its working totally fine. My only issue is that I am not able to see the publish dialog box (as mentioned in the tutorial), where as I want it to be shown as I want user to modify the contents of the message. How do I do this?
这是我用来发布帖子的代码的快照.
Here is a snapshot of the code I am using to publish the post.
public void postToWall(String message){
Bundle parameters = new Bundle();
parameters.putString("message", message);
parameters.putString("description", "topic share");
try {
facebook.request("me");
String response = facebook.request("me/feed", parameters, "POST");
Log.d("Tests", "got response: " + response);
if (response == null || response.equals("") ||
response.equals("false")) {
showToast("Blank response.");
}
else {
showToast("Message posted to your facebook wall!");
}
finish();
} catch (Exception e) {
showToast("Failed to post to wall!");
e.printStackTrace();
finish();
}
}
具有
private static final String[] PERMISSIONS = new String[] {"publish_stream"};
我还发现有一个名为facebook.dialog()的东西,但我不知道在哪里以及如何使用它.
I also found that there is something called facebook.dialog() but I have no idea where and how to use it.
那么,如何显示发布"对话框?
So, how do I show the publish dialog box?
推荐答案
您使用的代码将在没有Dialog的情况下发布在墙上.
Code you used will publish on wall without Dialog.
使用下面的代码片段显示Dialog:
Use below code snippet to show Dialog :
private void post_facebook() {
Bundle parameters = new Bundle();
parameters.putString("method", "stream.publish");
JSONObject attachment = new JSONObject();
try {
attachment.put("message", "Messages");
attachment.put("name", "Check out");
attachment.put("href", "http://www.google.com");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
parameters.putString("attachment", attachment.toString());
authenticatedFacebook.dialog(Activity.this, "stream.publish",parameters, new TestUiServerListener());
}
public 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 {
Activity.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");
Activity.this.runOnUiThread(new Runnable() {
public void run() {
}
});
} 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();
}
}
经过身份验证的Facebook是Facebook对象.
Where authenticatedFacebook is Facebook object.
这篇关于在Android手机上使用最新的facebookSDK将Facebook与Android集成使用时,如何显示发布对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!