Android Facebook Messenger 的自定义 URI 方案
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25467445/
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
Custom URI Schemes for the Facebook Messenger
提问by Dev-iL
Given the recent "encouragement" by Facebook to migrate to a separate messenger app, and as a followup to the {very informative!} answer to the question on URL/URI schemes supported by the Facebook app, I've been wondering whether information regarding the Facebook messenger app custom protocolof fb-messenger://
is available.
鉴于Facebook最近“鼓励”迁移到单独的 Messenger 应用程序,以及作为对 Facebook 应用程序支持的 URL/URI 方案问题的{非常翔实!}回答的后续行动,我一直想知道有关Facebook的Messenger应用自定义协议的fb-messenger://
可用。
The functionality I was looking for was an ability to click a button that would open a FB-messenger chat windows with the user whose numeric Facebook ID is known. This also needed to work if the Facebook app (katana) is not installed on the device (i.e. only the messenger, orca).
我正在寻找的功能是能够单击一个按钮,该按钮将打开一个 FB-messenger 聊天窗口,该用户的数字 Facebook ID 是已知的。如果 Facebook 应用程序 ( katana) 未安装在设备上(即仅使用信使orca),这也需要工作。
I found an exampleof the desired deep linking(fb-messenger://user-thread/{user-id}
), but that didn't seem to work. I realized that FB has a tendency of revising the URIs every once in a while, since these are generally not supposed to be available to the public (as far as I understand).
我找到了所需深层链接( )的示例,但这似乎不起作用。我意识到 FB 有每隔一段时间修改 URI 的趋势,因为这些通常不应该向公众提供(据我所知)。fb-messenger://user-thread/{user-id}
回答by Dev-iL
After unsuccessfully searching for this information, I've decided to make a list of my own. Below is what I managed to gather so far, along with a few explanations:
在搜索此信息失败后,我决定制作一个我自己的列表。以下是我迄今为止设法收集的内容,以及一些解释:
This is updated for version 141.0.0.25.76(October 21, 2017).
这是针对版本141.0.0.25.76(2017 年 10 月 21 日)更新的。
fb-messenger://accounts
fb-messenger://active_now
fb-messenger://addcard
fb-messenger://addmembers
fb-messenger://android_date_time
fb-messenger://android_storage
fb-messenger://autocompose
fb-messenger://autocompose_payment
fb-messenger://bots/get_started/?page_id=%s&cta_id=%s
fb-messenger://business
fb-messenger://business/
fb-messenger://business_extensions
fb-messenger://buy/mc?item_id={#%s}
fb-messenger://callsearch
fb-messenger://commerce/
fb-messenger://compose
fb-messenger://contactmigration
fb-messenger://contacts
fb-messenger://contacts/add_contacts
fb-messenger://contactuploadoptin
fb-messenger://direct_share
fb-messenger://drawoverotherapps
fb-messenger://games
fb-messenger://groupcompose
fb-messenger://groupstab
fb-messenger://groupthreadfbid/
fb-messenger://groupthreadfbid/%s
fb-messenger://ig_contact_import
fb-messenger://installupdate
fb-messenger://instant_article/?article_id=
fb-messenger://instant_article/?article_id=%s
fb-messenger://invite
fb-messenger://join_request
fb-messenger://mai
fb-messenger://messagerequests
fb-messenger://messagesearch
fb-messenger://montage
fb-messenger://montage_composer
fb-messenger://montage_mediapicker
fb-messenger://montageaudiencepicker
fb-messenger://montagecomposer
fb-messenger://networkempathy
fb-messenger://new
fb-messenger://newuser/
fb-messenger://newuser/signup?provider_name=%s&provider_page_fbid=%s
fb-messenger://nfc
fb-messenger://omni_m
fb-messenger://opengrouppreview
fb-messenger://opengrouppreview?group_preview_hash=
fb-messenger://optimistic
fb-messenger://optimistic/%s
fb-messenger://payments
fb-messenger://payments/
fb-messenger://platform
fb-messenger://platform/cta/postback/?cta_id=%s
fb-messenger://platform/share/?cta_id=%s
fb-messenger://ride_map/{%s}
fb-messenger://roomcompose
fb-messenger://rtccall
fb-messenger://sampleflows
fb-messenger://settings
fb-messenger://settings/datasaver
fb-messenger://settings/messengeronlybackup
fb-messenger://settings/montage
fb-messenger://settings/notifications
fb-messenger://settings/people
fb-messenger://settings/phoneevents
fb-messenger://settings/profilepicture
fb-messenger://settings/tincan
fb-messenger://share < Used for sharing multimedia, contains
several extras. See more info below.
fb-messenger://sms
fb-messenger://sms/
fb-messenger://sms/%s
fb-messenger://sms-bridge
fb-messenger://sms-takeover
fb-messenger://sms-takeover/nux?context=%s
fb-messenger://sms-takeover/nux?context=%s&thread_id=%s
fb-messenger://sms-takeover/sms_anonymous_chat_head
fb-messenger://stickerstore
fb-messenger://thread/ < Deprecated
fb-messenger://threadkeystring
fb-messenger://threads
fb-messenger://threadsettings
fb-messenger://user
fb-messenger://user/
fb-messenger://user/%s < Opens chathead/conversation with user %s, where
%s is the numeric fb user id. Using a username
string here crashes the orca app.
fb-messenger://user/%s?ref=%s&ref_source=%s
fb-messenger://verifyphonenux
fb-messenger://voip
fb-messenger://wave
Here are some URI schemes whose purpose in this app I don't know:
以下是一些我不知道在这个应用程序中的用途的 URI 方案:
fb://
- see possible URIs of this scheme here.fb-work://
fbinternal://
fb-messenger-secure://
dialtone://
fb://
-在此处查看此方案的可能 URI 。fb-work://
fbinternal://
fb-messenger-secure://
dialtone://
Investigation of fb-messenger://share
(from older version of this post - may be invalid):
调查fb-messenger://share
(来自这篇文章的旧版本 -可能无效):
- Has a
StringExtra
calledShareType
that can be:ShareType.invite
,ShareType.forward
,ShareType.regular
. - Has an optional(?)
StringExtra
calledShareType.invitedUser
. - Has an optional(?)
StringExtra
calledShareType.invitedUserDisplayName
. - Has an optional(?)
StringExtra
calledShareType.inviteEntryPoint
. - Has an optional(?)
StringExtra
calledShareType.invitesSentBroadcastAction
. - (several others)
- 有一个
StringExtra
调用ShareType
可以是:ShareType.invite
,ShareType.forward
,ShareType.regular
。 - 有一个可选的(?)
StringExtra
称为ShareType.invitedUser
. - 有一个可选的(?)
StringExtra
称为ShareType.invitedUserDisplayName
. - 有一个可选的(?)
StringExtra
称为ShareType.inviteEntryPoint
. - 有一个可选的(?)
StringExtra
称为ShareType.invitesSentBroadcastAction
. - (其他几个)
In the case of ShareType.forward
:
在以下情况下ShareType.forward
:
- Has an
Extra
with the tag"attachment"
OR"message"
. - Has an
Extra
with the tag"trigger"
.
- 有一个
Extra
带有标记"attachment"
OR"message"
。 - 有一个
Extra
带标签的"trigger"
。
Extra
fields of a share Intent
(tag : type):
Extra
共享字段Intent
(标签:类型):
android.intent.extra.TEXT
: Stringattachment
: Parcelablemessage
: Parcelablepage_name
: Stringpage_post_id
: Stringpage_target
: Longsend_as_message_entry_point
: Stringshare_attachment_url
: Stringshare_caption
: Stringshare_description
: Stringshare_fbid
: Stringshare_link_url
: Stringshare_media_url
: Stringshare_return_to_fb4a
: Booleanshare_robotext
: Stringshare_story_url
: Stringshare_title
: StringShareType
: Stringtarget_recipients
: StringArraytitle
: Stringtrigger
: String
android.intent.extra.TEXT
:字符串attachment
: 可包裹message
: 可包裹page_name
:字符串page_post_id
:字符串page_target
:长send_as_message_entry_point
:字符串share_attachment_url
:字符串share_caption
:字符串share_description
:字符串share_fbid
:字符串share_link_url
:字符串share_media_url
:字符串share_return_to_fb4a
:布尔值share_robotext
:字符串share_story_url
:字符串share_title
:字符串ShareType
:字符串target_recipients
:字符串数组title
:字符串trigger
:字符串
The required functionality may be achieved by using fb-messenger://user/{user-id}
instead of fb-messenger://user-thread/{user-id}
.
可以通过使用fb-messenger://user/{user-id}
代替来实现所需的功能fb-messenger://user-thread/{user-id}
。
Notethat {user-id}
is the user's global numeric ID(e.g. for Zuck it's 4
), which can be obtained (as of Nov. 2015) by parsing the html document that corresponds to the person's user name (e.g. for Zuck it's https://www.facebook.com/zuck
) and extracting the "entity_id"
that is found inside.
请注意,这{user-id}
是用户的全局数字 ID(例如Zuck it's4
),可以通过解析与此人的用户名(例如Zuck it'shttps://www.facebook.com/zuck
)对应的 html 文档并提取"entity_id"
找到的来获得(截至 2015 年 11 月)里面。
According to my latest test, app-scoped user IDs, which are usually the IDs available to developers, do not work for this!
根据我的最新测试,应用程序范围的用户 ID(通常是开发人员可用的 ID)对此不起作用!
Below is a python3 script that extracts the global ID for a known username (credit: Paul Schreiber):
下面是一个提取已知用户名的全局 ID 的 python3 脚本(来源:Paul Schreiber):
#!/usr/bin/python
import requests
import re
url = 'https://www.facebook.com/zuck'
idre = re.compile('"entity_id":"([0-9]+)"')
page = requests.get(url)
print(idre.findall(page.content.decode()))
Alternatively, this sitecan be used to achieve the same thing.
或者,此站点可用于实现相同的目的。
Please also note that this method is not officially supportedand might even get your app banned by FB.
另请注意,此方法不受官方支持,甚至可能会导致您的应用被 FB 禁止。
回答by SirNarsh
With current version Facebook on android automatically ask user to open the app or open in chrome when you use their domain www.messenger.com It's better to just redirect user to this url and let facebook handle it
使用当前版本的 android 上的 Facebook,当您使用他们的域 www.messenger.com 时,会自动要求用户打开应用程序或在 chrome 中打开最好将用户重定向到这个 url 并让 facebook 处理它
https://www.messenger.com/t/{username-or-page-name-here}
https://www.messenger.com/t/{username-or-page-name-here}
Intent intent;
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.messenger.com/t/{username-or-page-name-here}"));
startActivity(intent);
回答by ethannguyens
This simply share a link
这只是分享一个链接
<a href="fb-messenger://share?link=encodedLink"></a>
回答by Abhilash
Using chrome intents for Android: The below code opens FB messenger if installed. Else redirects to fallback URL.
为 Android 使用 chrome 意图:如果安装,以下代码将打开 FB messenger。否则重定向到后备 URL。
<a href="intent://user/<yourid>/#Intent;scheme=fb-messenger;package=com.facebook.orca;S.browser_fallback_url=http://yourfllbackweburl;end"> Open Messenger</a>
回答by waghydjemy
I know it is late but i hope it can help others
我知道已经晚了,但我希望它可以帮助其他人
For my case i wanted to open my page messenger bubble if installed of course
对于我的情况,如果安装了,我想打开我的页面信使气泡
So here what worked for me :
所以这里对我有用:
messengerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String messengerUrl ;
if (isMessengerAppInstalled()) {
Toast.makeText(ServiceClient.this, "messenger is installed , open app bubble", Toast.LENGTH_SHORT).show();
messengerUrl = "fb-messenger://user/475527699675914/";
} else {
Toast.makeText(ServiceClient.this, "messenger is not installed , open messenger in browser", Toast.LENGTH_SHORT).show();
messengerUrl = "https://www.messenger.com/t/475527699675914/";
}
Intent messengerIntent = new Intent(Intent.ACTION_VIEW);
messengerIntent.setData(Uri.parse(messengerUrl));
startActivity(messengerIntent);
}
});
public boolean isMessengerAppInstalled() {
try {
getApplicationContext().getPackageManager().getApplicationInfo("com.facebook.orca", 0);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}