0

I'm developing a material design app.

I want to open my app's facebook page when user clicks on the 'like on facebook' text (layout) in my app.

I've managed to open the facebook app but I am unable to figure out how can I open my page directly!

Here's what I've done so far:

LinearLayout linearLayoutFacebookContainer = (LinearLayout) findViewById(R.id.facebook_container);
        linearLayoutFacebookContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final Handler handler3 = new Handler();
                handler3.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        Intent facebookIntent = getPackageManager().getLaunchIntentForPackage("com.facebook.katana");
                        if (facebookIntent != null) {
                            // We found the activity now start the activity
                            facebookIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            facebookIntent.setData(Uri.parse("https://www.facebook.com/HumaneHelper/"));
                            startActivity(facebookIntent);
                        } else {
                            // Bring user to the market or let them choose an app?
                            facebookIntent = new Intent(Intent.ACTION_VIEW);
                            facebookIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            facebookIntent.setData(Uri.parse("https://www.facebook.com/HumaneHelper/"));
                            startActivity(facebookIntent);
                        }
                    }
                }, 200);
            }
        });

Please let me know.

I'm a beginner, please cooperate.

Thanks in advance.

1 Answers1

0

fb://page/{id} is the way to go:

final String url = "fb://page/" + facebookID
Intent facebookAppIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
facebookAppIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(facebookAppIntent);

Are you sure you are using the ID number of your Facebook page and NOT the username?

What I mean is that if, for example, you want to open the Facebook page of Facebook itself (i.e. https://www.facebook.com/facebook) you have to use:

fb://page/20531316728

Since 20531316728 is the ID of the Facebook page (while facebook is the username).

If you don't know the ID of your Facebook page, you can retrieve it opening:

https://graph.facebook.com/{username}

Courtesy: Open Facebook page via Facebook app

Community
  • 1
  • 1
Valamburi M
  • 692
  • 4
  • 17
  • What is the ID here: `{ "error": { "message": "An access token is required to request this resource.", "type": "OAuthException", "code": 104, "fbtrace_id": "Eef40vN5d+6" } }` –  Nov 20 '15 at 05:51
  • Facebook Access Token for Pages, Please refer here: http://stackoverflow.com/a/8235011/2691974 – Valamburi M Nov 20 '15 at 09:02
  • May be this could also help you https://www.facebook.com/help/community/question/?id=378910098941520 – Valamburi M Nov 20 '15 at 09:13