Android 在指定的个人资料页面上打开 Facebook 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10788247/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Opening facebook app on specified profile page
提问by Jacek Kwiecień
I'm trying to use some code from SO but it fails:
我正在尝试使用 SO 中的一些代码,但失败了:
Those are uri's supposed to open the right section of the app.
这些是 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
What I want is to open facebook app on a profile I've specified. This is a code that I'm trying. The number is UID of the profile.
我想要的是在我指定的个人资料上打开 facebook 应用程序。这是我正在尝试的代码。数字是配置文件的 UID。
String uri = "facebook://facebook.com/wall?user=417079614970109";
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
Is it depreciated or what? How do I accomplish such task now?
是贬值了还是什么?我现在如何完成这样的任务?
回答by Zaid Daghestani
Actually it looks like this. These URIs only work with the most recent version of the facebook app. That's why we try catch.
实际上它看起来像这样。这些 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
}
}
In your Activity, to open it, call it like so:
在您的 Activity 中,要打开它,请像这样调用它:
Intent facebookIntent = getOpenFacebookIntent(this);
startActivity(facebookIntent);
回答by John
Is this not easier? For example within an onClickListener?
这不是更容易吗?例如在 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")));
}
PS. Get your id (the large number) from http://graph.facebook.com/[userName]
附注。从http://graph.facebook.com/[userName]获取您的 ID(大数)
回答by Tristan Richard
This no longer works
这不再有效
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/someProfile"));
Please try this instead
请试试这个
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href=https://www.facebook.com/someProfile"));
回答by Shailesh
There are so many question about this but this code is worked for me.Facebook changed there policy so for more detail please check this Facebook official GRAPH API EXPLORER PAGE
关于这个有很多问题,但这段代码对我有用。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);
回答by Jemo Mgebrishvili
For now it is not possible, Facebookhas been removed this functionality
目前不可能,Facebook已删除此功能
回答by Jorgesys
To do this we need the "Facebook page id", you can get it :
为此,我们需要“Facebook 页面 ID”,您可以获取它:
- from the page go to "About".
- go to "More Info" section.
- 从页面转到“关于”。
- 转到“更多信息”部分。
To opening facebook app on specified profile page,
要在指定的个人资料页面上打开 facebook 应用程序,
you can do this:
你可以这样做:
String facebookId = "fb://page/<Facebook Page ID>";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(facebookId)));
回答by abir99
For facebook page use like this: http://fb://page/87268309621xxxxFor personal id use like this: http://fb://profile/87268309621xxxx
对于 facebook 页面这样使用:http://fb://page/87268309621xxxx对于这样的个人 ID 使用:http://fb://profile/87268309621xxxx