4

我的应用程序会生成按生日排列的朋友的自定义列表视图。所以我用过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让我感到困惑。

在那个问题中:

适用于 Android 的 Facebook SDK 提供了一种方法,可让您将应用中的故事发布到用户的时间线。您还可以使用此方法代表您的用户发布状态更新。此方法使用 Graph API,是使用 Feed Dialog 的替代方法

http://developers.facebook.com/docs/howtos/androidsdk/3.0/publish-to-feed/

还:

永远不要使用 Graph-API 在朋友的墙上发帖。因为它在 2013 年 2 月 6 日之后被禁用。FB 建议您使用 Feed Dialog 在朋友或您自己的墙上发帖。这是如何使用提要对话框的链接:http: //developers.facebook.com/docs/howtos/androidsdk/3.0/feed-dialog

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

4

2 回答 2

3

我找到了解决方案。您只需要添加“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();
        }
    }

对于许多朋友的墙贴:

RequestsDialogBu​​ilder 而不是 FeedDialogBu​​ilder 因为第二个只允许参数“to”上有多个 id,而第一个可以接收很多(虽然不确定限制,但我认为大约是 50)

学分:gian1200

于 2013-04-24T09:19:53.347 回答
0

可能重复...我认为您应该检查 Demo FB 提供的 Facebook - 从 Android 应用程序发布到墙上

更新:

嗯,有这个。 http://developers.facebook.com/docs/howtos/androidsdk/3.0/publish-to-feed/

Facebook 实际上建议使用 Feed。一探究竟

于 2013-04-23T16:51:34.333 回答