Getting the User ID

To identify and authenticate the user and personalize the resulting experience, you can call MessengerExtensions.getUserID to get a page-scoped user ID (PSID).

<script>
    MessengerExtensions.getUserID(function success(uids) {
  	// User ID was successfully obtained. 
      	var psid = uids.psid;
  
    }, function error(err, errorMessage) {      
  	// Error handling code
    });    
</script>

After obtaining the ID, you may wish to call the user profile API to get more info about the user, like name, gender, and profile picture.

Bots that transmit the user ID for the purpose of performing an action on the server and require the ability to verify it should instead use the getContext() API.


Parameters

Parameter Description Type Required

success callback

This function will be called if getUserID is successful.

function

Yes

error callback

This function will be called if there is an error.

function

Yes

Result

Field Description Type

uids

Object containing user ids

Object

uids fields

Field Description Type

psid

Page-scoped user ID

Number