Custom URI Schemes for the Facebook Messenger

后端 未结 5 1586
野性不改
野性不改 2020-11-27 16:21

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

相关标签:
5条回答
  • 2020-11-27 16:42

    This simply share a link

    <a href="fb-messenger://share?link=encodedLink"></a>
    
    0 讨论(0)
  • 2020-11-27 16:42

    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;
            }
        }
    
    0 讨论(0)
  • 2020-11-27 16:44

    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

    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);
    
    0 讨论(0)
  • 2020-11-27 16:48

    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).

    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:

    • fb:// - see possible URIs of this scheme here.
    • fb-work://
    • fbinternal://
    • fb-messenger-secure://
    • dialtone://

    Investigation of fb-messenger://share (from older version of this post - may be invalid):

    • Has a StringExtra called ShareType that can be: ShareType.invite, ShareType.forward, ShareType.regular.
    • Has an optional (?) StringExtra called ShareType.invitedUser.
    • Has an optional (?) StringExtra called ShareType.invitedUserDisplayName.
    • Has an optional (?) StringExtra called ShareType.inviteEntryPoint.
    • Has an optional (?) StringExtra called ShareType.invitesSentBroadcastAction.
    • (several others)

    In the case of ShareType.forward:

    • Has an Extra with the tag "attachment" OR "message".
    • Has an Extra with the tag "trigger".

    Extra fields of a share Intent (tag : type):

    • android.intent.extra.TEXT : String
    • attachment : Parcelable
    • message : Parcelable
    • page_name : String
    • page_post_id : String
    • page_target : Long
    • send_as_message_entry_point : String
    • share_attachment_url : String
    • share_caption : String
    • share_description : String
    • share_fbid : String
    • share_link_url : String
    • share_media_url : String
    • share_return_to_fb4a : Boolean
    • share_robotext : String
    • share_story_url : String
    • share_title : String
    • ShareType : String
    • target_recipients : StringArray
    • title : String
    • trigger : String

    The required functionality may be achieved by using fb-messenger://user/{user-id} instead of fb-messenger://user-thread/{user-id}.

    Note that {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.

    According to my latest test, app-scoped user IDs, which are usually the IDs available to developers, do not work for this!

    Below is a python3 script that extracts the global ID for a known username (credit: 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 site can be used to achieve the same thing.

    Please also note that this method is not officially supported and might even get your app banned by FB.

    0 讨论(0)
  • 2020-11-27 16:51

    Using chrome intents for Android: The below code opens FB messenger if installed. Else redirects to fallback URL.

    <a href="intent://user/<yourid>/#Intent;scheme=fb-messenger;package=com.facebook.orca;S.browser_fallback_url=http://yourfllbackweburl;end"> Open Messenger</a>
    
    0 讨论(0)
提交回复
热议问题