在指定的个人资料页面上打开Facebook应用

Jac*_*ień 17 android facebook android-intent

我正在尝试使用SO中的一些代码,但它失败了:

那些是uri应该打开应用程序的正确部分.

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 
Run Code Online (Sandbox Code Playgroud)

我想要的是在我指定的配置文件上打开Facebook应用程序.这是我正在尝试的代码.该数字是配置文件的UID.

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

是折旧还是什么?我现在如何完成这项任务?

Zai*_*ani 52

实际上它看起来像这样.这些URI仅适用于最新版本的facebook应用程序.这就是我们尝试捕获的原因.

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
    }
}
Run Code Online (Sandbox Code Playgroud)

在您的活动中,要打开它,请调用它:

Intent facebookIntent = getOpenFacebookIntent(this);
startActivity(facebookIntent);
Run Code Online (Sandbox Code Playgroud)

  • 只是为了澄清配置文件后的数字是用户的facebook id.如果您只有一个用户名,可以从http://graph.facebook.com/ [userName]的id字段中获取id. (2认同)

Joh*_*ohn 11

这不容易吗?例如在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")));

      }
Run Code Online (Sandbox Code Playgroud)

PS.从http://graph.facebook.com/ [userName]获取您的ID(大号)


Tri*_*ard 10

这不再有效

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/someProfile"));
Run Code Online (Sandbox Code Playgroud)

请试试这个

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