【问题标题】:Open facebook page from android app (in facebook version > v11)从 android 应用程序打开 facebook 页面(在 facebook 版本 > v11 中)
【发布时间】:2014-08-22 23:51:46
【问题描述】:

我曾经使用以下代码从我的应用程序打开我的 facebook 页面,但从 2014 年 6 月 21 日发布的 facebook v11.0.0.11.23 开始,这不再起作用,知道如何在新的 facebook 应用程序中打开页面? 需要注意的是,它现在打开了 facebook 应用程序,但没有打开指定的页面,它在最新更新之前可以正常工作

public void openFacebookPage() {
    Intent intent = null;
    try {
        context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/<id here>"));
        //tried this also
        //intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/<id here>"));
    } catch (Exception e) {
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/<name here>"));
    }
    context.startActivity(intent);
}

【问题讨论】:

    标签: android facebook


    【解决方案1】:

    在 Facebook 版本 11.0.0.11.23 (3002850) 中不再支持 fb://profile/ 和 fb://page/。我反编译了 Facebook 应用程序,并提出了以下解决方案:

    String facebookUrl = "https://www.facebook.com/JRummyApps";
    try {
        int versionCode = getPackageManager().getPackageInfo("com.facebook.katana", 0).versionCode;
        if (versionCode >= 3002850) {
            Uri uri = Uri.parse("fb://facewebmodal/f?href=" + facebookUrl);
            startActivity(new Intent(Intent.ACTION_VIEW, uri));;
        } else {
            // open the Facebook app using the old method (fb://profile/id or fb://page/id)
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/336227679757310")));
        }
    } catch (PackageManager.NameNotFoundException e) {
        // Facebook is not installed. Open the browser
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(facebookUrl)));
    }
    

    编辑: 已经有一段时间了,看起来 fb://profile 和 fb://page 不再受支持。以下是我在生产中一直使用的方法:

    /**
     * Intent to open the official Facebook app. If the Facebook app is not installed then the
     * default web browser will be used.</p>
     * 
     * Example usage:</p>
     * <code>newFacebookIntent(context.getPackageManager(), "https://www.facebook.com/JRummyApps");</code></p>
     * 
     * @param pm
     *            Instance of the {@link PackageManager}.
     * @param url
     *            The full URL to the Facebook page or profile.
     * @return An intent that will open the Facebook page/profile.
     */
    public static Intent newFacebookIntent(PackageManager pm, String url) {
        Uri uri;
        try {
            pm.getPackageInfo("com.facebook.katana", 0);
            // http://stackoverflow.com/a/24547437/1048340
            uri = Uri.parse("fb://facewebmodal/f?href=" + url);
        } catch (PackageManager.NameNotFoundException e) {
            uri = Uri.parse(url);
        }
        return new Intent(Intent.ACTION_VIEW, uri);
    }
    

    【讨论】:

    • 谢谢我试过了,它可以通过在本机 facebook 应用程序中加载网页来正常工作,尽管我更喜欢更集成的解决方案(与从 facebook 应用程序中打开页面相同的页面布局),我会稍等,如果没有提供更好的解决方案,我会接受这个。谢谢
    • 酷。我希望有人想出更好的东西。这需要一些挖掘才能找到。
    • 我使用了您的代码,尽管它打开了 Facebook 应用程序,但我收到消息“找不到页面”。我的使用有什么问题?我知道 url 是正确的,因为我在另一个意图中使用它并且它有效!
    • 我找到了。如果您尚未从此处更改页面的用户名,则首先必须更改页面的用户名:www.facebook.com/username
    • 这个答案需要首先出现在谷歌搜索中。现在出现的所有答案都是旧的,不再起作用了。感谢您对此进行调查...它自此日期起有效!
    猜你喜欢
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-09
    相关资源
    最近更新 更多