MessengerExtensions.getContext()

SDK tiện ích Messenger

Phương pháp này là một phần của Messenger Extensions SDK. Để biết thông tin về cách đưa SDK vào trang web của bạn, hãy xem Thêm Messenger Extensions SDK.

Tính khả dụng

API này chỉ khả dụng trong Messenger trên v113+ trên Android và v114+ trên iOS.

Để kiểm tra tính khả dụng của API này trên một máy khách nhất định, hãy gọi getSupportedFeatures() và kiểm tra tài sản context trong phản hồi.

The getContext() method retrieves additional information about the person and the thread that opened the webview within Messenger. It is useful for creating interactive group experiences and games, as well as restricting any content that was intended to be shared only to a certain thread.

Method

MessengerExtensions.getContext(app_id, success, error)

Example

MessengerExtensions.getContext('YOUR_APP_ID', 
  function success(thread_context){
    // success
  },
  function error(err){
    // error
  }
);

Parameters

Parameter Type Description

app_id

String

Your app ID.

success

Function

Success callback function. Receives the thread context object as an argument.

error

Function

Error callback function. Called if Messenger was unable to retrieve the thread context.

thread_context Object

The thread_context object is passed to the success callback.

{
  "thread_type": "GROUP",
  "tid": "1411911565550430",
  "psid": "1293479104029354",
  "signed_request": "5f8i9XXH2hEaykXHKFvu-E5Nr6QRqN002JO7yl-w_9o.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImlzc3VlZF9hdCI6MTUwNDA0NjM4MCwicGFnZV9pZCI6NjgyNDk4MTcxOTQzMTY1LCJwc2lkIjoiMTI1NDQ1OTE1NDY4MjkxOSIsInRocmVhZF90eXBlIjoiVVNFUl9UT19QQUdFIiwidGlkIjoiMTI1NDQ1OTE1NDY4MjkxOSJ9"
}

Properties

Property Type Description

tid

String

The ID of the thread the webview was opened from.

thread_type

String

The type of thread the webview was openeed from. The possible types are:

USER_TO_PAGE: A conversation between a user and a page. USER_TO_USER: A conversation between two users. GROUP: A conversation between multiple users. Number of participants for such conversations can change from 1 to maximum supported by Messenger group capabilities.

psid

String

The page-scoped user ID for the person that opened the webview.

signed_request

String

A signed request containing the above information. Used to verify the authenticity of the thread context source.


For more information, see Validating signed_request.