How to open Facebook app on user timeline?

吃可爱长大的小学妹 提交于 2019-12-13 19:42:30

问题


I'm trying to open a facebook app, from my app, but i need it to go to specific user's timeline. I can open it in the phone browser it works fine, but i can't open it in facebook app... I know facebook changed the way it was before, i'm using facebook-android-sdk:4.6.0 This is my code:

public Intent getOpenFacebookIntent(String userId) {
        Log.e(TAG, "pid "+ userId);
        try {
            getPackageManager().getPackageInfo("com.facebook.katana", 0);
            return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/" + userId));

        } catch (Exception e) {
            return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/" + userId));

        }
    }

Thnx!


回答1:


Just do a little change

"https://www.facebook.com/profile.php?id=" + userId

Try this one.

Also, FYI: https://www.facebook.com/" + userId will work only when you pass username not userId.




回答2:


The only code that worked for me was:

public Intent getOpenFacebookIntent(String userId) {
        Log.e(TAG, "pid "+ userId);

        String facebookUrl = "https://www.facebook.com/"+userId;
        try {
            getPackageManager().getPackageInfo("com.facebook.katana", 0);

            return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href=" + facebookUrl));

        } catch (Exception e) {
            return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/app_scoped_user_id/" + userId));

        }
    }


来源:https://stackoverflow.com/questions/35082852/how-to-open-facebook-app-on-user-timeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!