如何在Android手机上使用最新的facebookSDK使用facebook与android集成时显示发布对话框 [英] how to show the publish dialog box when using facebook integration with android using latest facebookSDK on android mobiles

查看:138
本文介绍了如何在Android手机上使用最新的facebookSDK使用facebook与android集成时显示发布对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助这篇文章本教程我已经设法将我的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

以下是我用于发布帖子的代码的快照。 p>

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 please let me know how do I show the publish dialog box.

谢谢

Raj

推荐答案

您使用的代码将在墙上发布没有对话框。

Code you used will publish on wall without Dialog.

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..

使用以下代码片段显示对话框:

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();
    }
}

其中authenticatedFacebook是Facebook对象。

Where authenticatedFacebook is Facebook object.

这篇关于如何在Android手机上使用最新的facebookSDK使用facebook与android集成时显示发布对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆