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

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

问题描述

随着<帮助href="http://stackoverflow.com/questions/8878920/how-do-i-share-a-page-or-link-using-the-latest-facebook-sdk-for-android">this帖子和<一href="http://www.integratingstuff.com/2010/10/14/integrating-facebook-into-an-android-application/#comment-500"相对=nofollow>这个教程我设法在我与最新的FacebookSDK Android应用程序整合Facebook。我想发布一些内容,这样使用的教程及其工作完全正常......我唯一的问题是,我无法看到发布对话框(如提到的教程),在那里,我希望它显示为我希望用户修改消息的内容......如何做到这一点

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

这里是code快照,我使用发布帖子。

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.

感谢您

拉​​吉

推荐答案

code您使用将公布上墙没有对话。

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

使用下面code片段来显示对话框:

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.

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

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