Opening facebook app on specified profile page

后端 未结 7 1116
温柔的废话
温柔的废话 2020-12-24 14:20

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=         


        
相关标签:
7条回答
  • 2020-12-24 15:07

    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);
    
    0 讨论(0)
  • 2020-12-24 15:07

    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);
    
    0 讨论(0)
  • 2020-12-24 15:07

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

    0 讨论(0)
  • 2020-12-24 15:15

    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"));
    
    0 讨论(0)
  • 2020-12-24 15:15

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

    0 讨论(0)
  • 2020-12-24 15:15

    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)));
    
    0 讨论(0)
提交回复
热议问题