Dev-iL Dev-iL - 2 months ago 13
Android Question

Custom URI Schemes for the Facebook Messenger

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 protocol of

fb-messenger://
is available.

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

I found an example of 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).

Answer

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 39.0.0.23.150 (October 14, 2015).

fb-messenger://android_storage
fb-messenger://callsearch
fb-messenger://compose
fb-messenger://contacts
fb-messenger://contactuploadoptin
fb-messenger://conversationrequests
fb-messenger://groupcompose
fb-messenger://groupthreadfbid/
fb-messenger://groupthreadfbid/%s
fb-messenger://installupdate
fb-messenger://invite
fb-messenger://payments/addcard
fb-messenger://payments/settings
fb-messenger://rtccall
fb-messenger://settings
fb-messenger://settings/dataandstorage
fb-messenger://settings/notifications
fb-messenger://settings/profilepicture
fb-messenger://share                    < Used for sharing multimedia, contains 
                                        //several extras. See more info below.    
fb-messenger://stickerstore
fb-messenger://subscribe
fb-messenger://thread/                  < Deprecated
fb-messenger://threads
fb-messenger://threadsettings
fb-messenger://user/
fb-messenger://user/%s                  < Opens chathead/conversation with user %s
                                        //where %s is the user number. Using a text
                                        //string (e.g. username) crashes the orca app.
fb-messenger://verifyphonenux

fb-messenger-sametask://share
fb-messenger-secure://rtccall/audio/%s
fb-messenger-secure://rtccall/video/%s

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.