Lớp công cụ
RecommendationPages
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
Tóm Tắt
Mẫu mã
Tạo danh sách các mục được đề xuất
local RecommendationService = game:GetService("RecommendationService")
-- Định nghĩa yêu cầu để tạo danh sách đề xuất
local request: GenerateRecommendationItemListRequest = {
ConfigName = "MaximizeEngagement",
LocationId = "Lobby",
PageSize = 10
-- LƯU Ý: Bỏ chú thích và đặt CustomContexts.UserId cho script Server.
-- Không cần đặt cho script Local.
-- CustomContexts = {
-- ["UserId"] = tostring(player.UserId),
-- }
}
-- Gọi GenerateItemListAsync để lấy các trang đề xuất
local success, recommendationPages = pcall(function()
return RecommendationService:GenerateItemListAsync(request)
end)
if success then
-- Lấy trang hiện tại của các mục được đề xuất
local currentPage = recommendationPages:GetCurrentPage()
for _, item in ipairs(currentPage) do
print("ItemId: " .. item.ItemId)
print(" ReferenceId: " .. item.ReferenceId)
print(" TracingId: " .. item.TracingId)
end
else
warn("Lỗi RecommendationService: " .. tostring(recommendationPages))
end
--[[ Định dạng dữ liệu trả về cho mỗi mục trong trang
{
"ItemId": string,
"ReferenceId": string,
"TracingId": string,
"Creator": {
"CreatorId": number,
"CreatorType": Enum.CreatorType,
}?,
"Attributes": {
{
"AssetId": number?,
"Text": string?,
"Description": string?,
"SeekStartTime": number?,
"SeekEndTime": number?,
"TrimStartTime": number?,
"TrimEndTime": number?
}
}?,
"CustomTags": { string }?
}
--]]