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ặt hàng được đề xuất
local RecommendationService = game:GetService("RecommendationService")
-- Định nghĩa yêu cầu để tạo danh sách gợi ý
local request: GenerateRecommendationItemListRequest = {
ConfigName = "MaximizeEngagement",
LocationId = "Lobby",
PageSize = 10
-- CHÚ Ý: 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 để nhận các trang gợi ý
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ặt hàng đượ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ặt hàng 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 }?
}
--]]