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

标签 android facebook facebook-graph-api

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

我四处搜索,但未能找到合适的方式来将启动 Facebook 应用程序的 Intent 传递到特定的帖子页面。因此,我决定尝试启动浏览器并导航到移动 Facebook 网站以查看特定帖子。我使用有关当前用户的信息、帖子的 ID 和它所属的 friend 的 ID 来构建 url 字符串。当我从新闻源浏览到浏览器中的页面时,此 url 与我看到的 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 应用程序到所选的帖子 Activity 。

最佳答案

我刚刚弄明白了。事实证明,我从新闻源请求到图形 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);

关于android - 如何链接到特定 Facebook 新闻源帖子的页面(在应用程序或浏览器中)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8761157/

相关文章:

ios - 如何在成功的 FB ShareDialog 帖子后获取帖子 ID

facebook - 在 Facebook Page Insights 中获取两个奇怪的数字

java - 如何替换 Activity 中的 textChangedListener

android - 每个基于 WebKit 的浏览器都会使使用 Omniture 的网站崩溃。为什么?

android - TextView 椭圆大小不工作

c# - 如何更改 XAMARIN 中 Picker 占位符的颜色?

facebook - 申请 Facebook 页面

iphone - 将应用程序帐户与 facebook 和 twitter 帐户关联

android - Sharing Intent 结合 Facebook SDK

java - 将 FacebookAPI/restfb 1.6 迁移到 1.36 会导致弃用警告和编译错误