Opening facebook app on specified profile page

2020-02-17 09:38发布

问题:

I'm trying to use some code from SO but it fails:

Those are uri's supposed to open the right section of the app.

facebook://facebook.com/info?user=544410940     (id of the user. "patrick.boos" won't work)
facebook://facebook.com/wall?user=544410940   (will only show the info if you have added it as 

What I want is to open facebook app on a profile I've specified. This is a code that I'm trying. The number is UID of the profile.

        String uri = "facebook://facebook.com/wall?user=417079614970109"; 
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        startActivity(intent);

Is it depreciated or what? How do I accomplish such task now?

回答1:

Actually it looks like this. These URIs only work with the most recent version of the facebook app. That's why we try catch.

public static Intent getOpenFacebookIntent(Context context) {

    try {
        context.getPackageManager()
                .getPackageInfo("com.facebook.katana", 0); //Checks if FB is even installed.
        return new Intent(Intent.ACTION_VIEW,
                Uri.parse("fb://profile/254175194653125")); //Trys to make intent with FB's URI
    } catch (Exception e) {
        return new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://www.facebook.com/arkverse")); //catches and opens a url to the desired page
    }
}

In your Activity, to open it, call it like so:

Intent facebookIntent = getOpenFacebookIntent(this);
startActivity(facebookIntent);


回答2:

Is this not easier? For example within an onClickListener?

    try{ 

        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/426253597411506"));
        startActivity(intent);

       }catch(Exception e){

         startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/appetizerandroid")));

      }

PS. Get your id (the large number) from http://graph.facebook.com/[userName]



回答3:

This no longer works

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/someProfile"));

Please try this instead

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href=https://www.facebook.com/someProfile"));


回答4:

For now it is not possible, Facebook has been removed this functionality



回答5:

There are so many question about this but this code is worked for me.Facebook changed there policy so for more detail please check this Facebook official GRAPH API EXPLORER PAGE

Intent intent = null;
    try {
        getPackageManager().getPackageInfo("com.facebook.katana", 0);
        String url = "https://www.facebook.com/"+idFacebook;
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href="+url));
    } catch (Exception e) {
        // no Facebook app, revert to browser
        String url = "https://facebook.com/"+idFacebook;
        intent = new Intent(Intent.ACTION_VIEW);
        intent .setData(Uri.parse(url));
    }
    this.startActivity(intent);


回答6:

To do this we need the "Facebook page id", you can get it :

  • from the page go to "About".
  • go to "More Info" section.

To opening facebook app on specified profile page,

you can do this:

 String facebookId = "fb://page/<Facebook Page ID>";
  startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(facebookId)));


回答7:

For facebook page use like this: http://fb://page/87268309621xxxx For personal id use like this: http://fb://profile/87268309621xxxx