【问题标题】:Opening facebook app on specified profile page在指定的个人资料页面上打开 Facebook 应用程序
【发布时间】:2012-06-03 00:47:48
【问题描述】:

我正在尝试使用 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 

我想要的是在我指定的个人资料上打开 facebook 应用程序。这是我正在尝试的代码。该数字是配置文件的 UID。

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

是贬值还是什么?我现在如何完成这样的任务?

【问题讨论】:

标签: android facebook android-intent


【解决方案1】:

其实是这样的。这些 URI 仅适用于最新版本的 facebook 应用程序。这就是我们尝试 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
    }
}

在你的 Activity 中,打开它,这样调用它:

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

【讨论】:

  • 非常感谢。我想很多线程都贬值了。我的 Facebook 就像 sentiapps 一样 :)
  • 这个方法怎么称呼?例如 getOpenFacebookIntent (??) - 上下文有什么用?
  • 只是为了澄清profile后面的数字是用户的facebook id。如果你只有一个用户名,你可以从graph.facebook.com/[userName]的id字段中获取id
  • 你也应该添加intent.setPackage("com.facebook.katana");它可以让facebook活动打开得更快!
  • 正如 stackoverflow.com/questions/4810803/… 中的 Jareds 回答中指定的那样,在版本 11+ 中,有一个新地址供 intetnt 打开 fb 应用程序:fb://facewebmodal/f?href=[FACEBOOK_URL] 并输入那里的正常网址。
【解决方案2】:

这不再有效

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

请试试这个

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

【讨论】:

  • 谢谢!但是打开 Facebook Messenger 呢?
  • Open Facebook Messenger 与此问题无关。问一个新的
【解决方案3】:

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

附言。从http://graph.facebook.com/[userName]获取你的id(大数)

【讨论】:

  • 非常感谢您的提示
  • 接受的答案将不会启动活动,因此如果失败则不会调用 onResume
【解决方案4】:

目前不可能,Facebook 已删除此功能

【讨论】:

  • 你能链接这个吗?
【解决方案5】:

对此有很多问题,但此代码对我有用。Facebook 更改了那里的政策,因此有关更多详细信息,请查看此 Facebook 官方 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】:

    为此,我们需要“Facebook page id”,你可以得到它:

    • 从页面转到“关于”。
    • 转到“更多信息”部分。

    要在指定的个人资料页面上打开 facebook 应用程序,

    你可以这样做:

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

    【讨论】:

      【解决方案7】:

      Facebook 页面使用如下:http://fb://page/87268309621xxxx 对于这样的个人 ID 使用:http://fb://profile/87268309621xxxx

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-09-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多