如何在网站上建立几个Facebook链接在Facebook本机应用程序中打开并自动生成Facebook个人资料或页面数字ID

时间:2016-07-13 16:26:45

标签: android facebook facebook-graph-api

我有以下Android链接的Facebook链接在本地Facebook应用程序中打开。它工作正常但仅适用于此处url = "fb://profile/100012746891816";给出的配置文件ID。 如果有人可以帮助和编辑我的代码并使其适用于网站上的多个Facebook个人资料或页面并自动生成Facebook ID。

这是如何通过php <a href="<?php echo "http://facebook.com/".$fbk; ?>">进行im链接$fbk包含Facebook页面或个人资料名称。

if (url.contains("http://facebook.com")) {
    Uri uri = Uri.parse(url);
    try {
        url = "fb://profile/100012746891816";
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity(intent);
    } catch(Exception e) {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
    }
    return true;
}

1 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情:

private static final String FB_BASE = "facebook.com/";

public void openFacebookProfile(String profileUrl){
    try{
        Uri uri = null;

        int versionCode = getPackageManager()
                .getPackageInfo("com.facebook.katana", 0)
                .versionCode;

        if(versionCode >= 3002850)
            uri = Uri.parse("fb://facewebmodal/f?href=" + profileUrl);
        else {
            String profileId = profileUrl.substring(profileUrl.indexOf(FB_BASE) + FB_BASE.length());

            uri = Uri.parse("fb://profile/" + profileId);
        }

        startActivity(new Intent(Intent.ACTION_VIEW, uri));
    }
    catch(Throwable e){
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(profileUrl)));
    }
}

只要URL包含“facebook.com/”,它就应该从末尾删除配置文件ID(假设没有尾随数据),然后通过正确的本机FB平台打开,或者默认使用Web。 / p>