如何链接到特定Facebook新闻源帖子的页面(在应用程序或浏览器中)?

时间:2012-01-06 16:36:06

标签: android facebook facebook-graph-api

在我的Android应用中,我使用Facebook SDK登录并显示来自用户新闻源的帖子。我想给他们评论或喜欢帖子的选项,但我不想实现它。因此,我的解决方案是允许用户点击帖子,然后将帖子加载到官方Facebook应用程序或移动Facebook网站。无论哪种方式对我都没问题。

我用Google搜索,无法找到合适的方式将Facebook应用程序发布到特定的帖子页面。所以,我决定尝试启动浏览器并导航到移动Facebook网站到特定的帖子。我使用有关当前用户的信息,帖子的ID以及它所属的朋友的id来构建url字符串。这个网址与我从我的新闻源浏览浏览器中的页面时看到的网址完全相同。像这样:

                String url = "http://m.facebook.com/#!/story.php?story_fbid=" + postId + "&id=" + friendId + "&_user=" + FBHelper.getCurrentUserId();
                Uri uri = Uri.parse(url);

                Intent intent = new Intent(Intent.ACTION_VIEW, uri);

                startActivity(intent);

但是,当浏览器加载时,我会看到一个页面,上面写着“抱歉,出现了问题。我们正在努力尽快修复此问题。”我试过touch.facebook.com和m.facebook.com。

我正在寻找任何解决方案,允许我打开移动网站到选定的帖子,或启动Facebook应用程序到选定的帖子活动。

1 个答案:

答案 0 :(得分:1)

我只想出了这个。事实证明,我从图表api的新闻源请求的json结果得到的帖子ID有额外的信息。我从新闻源结果中获得的帖子ID是“friendid_postid”。但是,在链接中,“story_fbid”标签应设置为postid部分。那就行了!

这是我使用的代码:

            String postId = idTextView.getText().toString();
            postId = postId.substring(postId.indexOf("_") + 1, postId.length());
            String friendId = friendIdTextView.getText().toString();


            String url = "http://m.facebook.com/#!/story.php?story_fbid=" + postId + "&id=" + friendId + "&_user=" + FBHelper.getCurrentUserId();
            Uri uri = Uri.parse(url);

            Intent intent = new Intent(Intent.ACTION_VIEW, uri);

            startActivity(intent);