问题
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