mattgmg1990
mattgmg1990

Reputation: 5876

How can I link to the page of a specific Facebook newsfeed post (in the application or browser)?

In my Android app, I log in using the Facebook SDK and display posts from the users' newsfeed. I want to give them the option to comment or like a post, but I don't want to implement that. So, my solution is to allow the user to click on the post, which will then load the post page in either the official Facebook App, or just the mobile facebook website. Either way is fine for me.

I googled around and was not able to find a suitable way to deliver an intent to launch the Facebook app to a specific post page. So, I decided to try to launch the browser and navigate to the mobile Facebook website to the specific post. I build the url string using information about the current user, the id of the post, and the id of the friend it belongs to. This url is exactly the same url I see when I browse to the page in my browser from my newsfeed. Like so:

                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);

However, when the browser loads, I get a page that says "Sorry, something went wrong. We're working on getting this fixed as soon as we can." I have tried both touch.facebook.com and m.facebook.com.

I am looking for any solution that will either allow me to open the mobile site to the chosen post, or to launch the Facebook app to the chosen post activity.

Upvotes: 1

Views: 1161

Answers (1)

mattgmg1990
mattgmg1990

Reputation: 5876

I just figured this out. It turns out that the post id that I got from the json result of a newsfeed request to the graph api has extra information. The post id that I got from the newsfeed result is in the form "friendid_postid." In the link, however, the "story_fbid" tag should be set to just the postid portion. Then it works!

This is the code I used:

            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);

Upvotes: 1

Related Questions