Android:Facebook 3.0使用FQL请求响应在朋友墙上发布(截至2013年4月23日)

我的应用生成他们的生日安排的朋友的自定义列表视图.所以我使用了SELECT name,uid,pic_square,birthday_date FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1 = me())order by birthday_date.

现在,当用户点击朋友(从列表视图)时,它将提示用户他/她是否要发布到该朋友墙.我知道如何以旧的方式做到这一点,但我因为How to send a post to Facebook friend’s wall android SDK 3.0而变得混乱.

在那个问题中:

The Facebook SDK for Android provides a method to let you publish
stories from your app to a user’s timeline. You can also use this
method to post a status update on your user’s behalf. This method uses
the Graph API, and is an alternative to using the Feed Dialog

07001

也:

never use Graph-API for posting on friend’s wall. because it is disabled after 6, Feb 2013. FB recommend u to use Feed Dialog for posting on friend’s or your own wall. this is the link for how to use Feed Dialog : 07002

我已经看到了这两个链接,但两者都只显示了如何在自己的墙上发布.任何人都可以给我
一个很好的最新例子,或者至少,指出我如何通过Facebook Android SDK 3.x使用FQL请求响应发布到您的朋友墙上的正确方向(截至当前版本为3.0.2b)?

最佳答案
我找到了解决方案.您只需要添加“to”和“from”参数.以下是我的样本:

对于发布给单个朋友的墙贴:

    private void publishFeedDialog(String friend_uid) {
        Session session = Session.getActiveSession();
        if (!hasPublishPermission()) {
            // We don't have the permission to post yet.
            session.requestNewPublishPermissions(new Session.NewPermissionsRequest(this, WRITE_PERMISSION));
        }
        if (user != null && friend_uid != null && hasPublishPermission()) {

            final Activity activity = this;
            Bundle params = new Bundle();
            //This is what you need to post to a friend's wall
            params.putString("from", "" + user.getId());
            params.putString("to", friend_uid);
            //up to this
            params.putString("name", "Facebook SDK for Android");
            params.putString("caption", "Build great social apps and get more installs.");
            params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
            params.putString("link", "https://developers.facebook.com/android");
            params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
            WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(this, Session.getActiveSession(), params))
                    .setOnCompleteListener(new OnCompleteListener() {

                    @Override
                    public void onComplete(Bundle values, FacebookException error) {
                        if (error == null) {
                            // When the story is posted, echo the success
                            // and the post Id.
                            final String postId = values.getString("post_id");
                            if (postId != null) {
                                Toast.makeText(activity,
                                    "Posted story, id: "+postId,
                                    Toast.LENGTH_SHORT).show();
                            } else {
                                // User clicked the Cancel button
                                Toast.makeText(activity, 
                                    "Publish cancelled", 
                                    Toast.LENGTH_SHORT).show();
                            }
                        } else if (error instanceof FacebookOperationCanceledException) {
                            // User clicked the "x" button
                            Toast.makeText(activity, 
                                "Publish cancelled", 
                                Toast.LENGTH_SHORT).show();
                        } else {
                            // Generic, ex: network error
                            Toast.makeText(activity, 
                                "Error posting story", 
                                Toast.LENGTH_SHORT).show();
                        }
                    }

                }).build();
            feedDialog.show();
        }
    }

对于许多朋友的贴墙:

RequestsDialogBuilder instead of FeedDialogBuilder because the second one only allows multiple ids on the parameter “to”, while the first one can receive many (not sure about the limit though, but I think is about 50)

学分:gian1200

转载注明原文:Android:Facebook 3.0使用FQL请求响应在朋友墙上发布(截至2013年4月23日) - 代码日志